avoid deprecated IOLoop.current() call without running loop

This commit is contained in:
Thomas Grainger 2022-01-18 11:15:52 +00:00
parent e461599184
commit 020c2f3fe0
No known key found for this signature in database
GPG Key ID: 2241857EB9DA2BC6
4 changed files with 29 additions and 11 deletions

View 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

View 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()

View 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:

View 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