]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
avoid deprecated IOLoop.current() call without running loop 3101/head
authorThomas Grainger <tagrain@gmail.com>
Tue, 18 Jan 2022 11:15:52 +0000 (11:15 +0000)
committerThomas Grainger <tagrain@gmail.com>
Wed, 19 Jan 2022 11:22:23 +0000 (11:22 +0000)
README.rst
docs/guide/running.rst
docs/guide/structure.rst
docs/index.rst

index 2c9561d527e9f6dd214c07416a8f0d2a9b3f98c6..9b33a10bd4d825cfb0e3a529ca495ace9b82834e 100644 (file)
@@ -20,7 +20,8 @@ Here is a simple "Hello, world" example web app for Tornado:
 
 .. code-block:: python
 
-    import tornado.ioloop
+    import asyncio
+
     import tornado.web
 
     class MainHandler(tornado.web.RequestHandler):
@@ -32,10 +33,13 @@ Here is a simple "Hello, world" example web app for Tornado:
             (r"/", MainHandler),
         ])
 
-    if __name__ == "__main__":
+    async def main():
         app = make_app()
         app.listen(8888)
-        tornado.ioloop.IOLoop.current().start()
+        await asyncio.Event().wait()
+
+    if __name__ == "__main__":
+        asyncio.run(main())
 
 This example does not use any of Tornado's asynchronous features; for
 that see this `simple chat room
index 8cf34f05024c0fd36d4d69708de3864be7ba3320..f7fd26443b42af4995d678d5ea663fdce847f96c 100644 (file)
@@ -8,10 +8,16 @@ configuring a WSGI container to find your application, you write a
 
 .. testcode::
 
-    def main():
+    import asyncio
+
+    async def amain():
         app = make_app()
         app.listen(8888)
-        IOLoop.current().start()
+        await asyncio.Event().wait()
+
+
+    def main():
+        asyncio.run(amain())
 
     if __name__ == '__main__':
         main()
index 407edf414b62b0810d5402a1b68c17013df03a60..1c9a012a44ac54e01473a89aeac7250666bbdf09 100644 (file)
@@ -16,7 +16,8 @@ A minimal "hello world" example looks something like this:
 
 .. testcode::
 
-    import tornado.ioloop
+    import asyncio
+
     import tornado.web
 
     class MainHandler(tornado.web.RequestHandler):
@@ -28,10 +29,13 @@ A minimal "hello world" example looks something like this:
             (r"/", MainHandler),
         ])
 
-    if __name__ == "__main__":
+    async def main():
         app = make_app()
         app.listen(8888)
-        tornado.ioloop.IOLoop.current().start()
+        await asyncio.Event().wait()
+
+    if __name__ == "__main__":
+        asyncio.run(main())
 
 .. testoutput::
    :hide:
index 7877be8c3b08553c37cfa816287d85abf4cbdb5a..e8e50e8d942a33c38352d8f6225452a846ba30f1 100644 (file)
@@ -31,7 +31,8 @@ Hello, world
 
 Here is a simple "Hello, world" example web app for Tornado::
 
-    import tornado.ioloop
+    import asyncio
+
     import tornado.web
 
     class MainHandler(tornado.web.RequestHandler):
@@ -43,10 +44,13 @@ Here is a simple "Hello, world" example web app for Tornado::
             (r"/", MainHandler),
         ])
 
-    if __name__ == "__main__":
+    async def main():
         app = make_app()
         app.listen(8888)
-        tornado.ioloop.IOLoop.current().start()
+        await asyncio.Event().wait()
+
+    if __name__ == "__main__":
+        asyncio.run(main())
 
 This example does not use any of Tornado's asynchronous features; for
 that see this `simple chat room