diff --git a/README.rst b/README.rst index 2c9561d5..9b33a10b 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 8cf34f05..f7fd2644 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 407edf41..1c9a012a 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 7877be8c..e8e50e8d 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