From: Thomas Grainger Date: Tue, 18 Jan 2022 11:15:52 +0000 (+0000) Subject: avoid deprecated IOLoop.current() call without running loop X-Git-Tag: v6.2.0b1~30^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=020c2f3fe0fad3c66adefbe4b690f89a71baf4d2;p=thirdparty%2Ftornado.git avoid deprecated IOLoop.current() call without running loop --- diff --git a/README.rst b/README.rst index 2c9561d52..9b33a10bd 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/docs/guide/running.rst b/docs/guide/running.rst index 8cf34f050..f7fd26443 100644 --- a/docs/guide/running.rst +++ b/docs/guide/running.rst @@ -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() diff --git a/docs/guide/structure.rst b/docs/guide/structure.rst index 407edf414..1c9a012a4 100644 --- a/docs/guide/structure.rst +++ b/docs/guide/structure.rst @@ -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: diff --git a/docs/index.rst b/docs/index.rst index 7877be8c3..e8e50e8d9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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