from tornado.platform.asyncio import AsyncIOMainLoop
import asyncio
AsyncIOMainLoop().install()
asyncio.get_event_loop().run_forever()
install method throws assertion:
packages/tornado/ioloop.py", line 176, in install
assert not IOLoop.initialized()
AssertionError
Those four lines on their own are fine. If you're getting this error then it means that something _before_ these lines is initializing the IOLoop. Look through your code for anything that accesses IOLoop.current() or IOLoop.instance() at import time.
indeed there was a call of tornado.web.Application.listen, which leads to IOLoop.current() in tcpserver.add_sockets
the debug=True or autoreload=True option will also init ioloop.
and I should put:
from tornado.platform.asyncio import AsyncIOMainLoop
AsyncIOMainLoop().install()
in the first two line of the application file.
and at last, write
application = Application()
options.parse_command_line()
application.listen(options.port)
asyncio.get_event_loop().run_forever()
to start my application.
Those four lines on their own are fine. If you're getting this error then it means that something _before_ these lines is initializing the IOLoop. Look through your code for anything that accesses
IOLoop.current()orIOLoop.instance()at import time.
thank you work for me
Most helpful comment
the
debug=Trueorautoreload=Trueoption will also init ioloop.and I should put:
in the first two line of the application file.
and at last, write
to start my application.