-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task was destroyed but it is pending #3047
Comments
Could you please paste your code |
Which version of Tornado are you using? That snippet of code looks fine, but of course there's very little to it. The problem could be elsewhere. Are you trying to shut down your application or is it still running while this message is logged? |
The Tornado version is 6.1 |
Per the warning in the asyncio documentation, we need to hold a strong reference to all asyncio Tasks to prevent premature GC. Following discussions in cpython (python/cpython#91887), we hold these references on the IOLoop instance to ensure that they are strongly held but do not cause leaks if the event loop itself is discarded. This is expected to fix all of the various "task was destroyed but it is pending" warnings that have been reported. The IOLoop._pending_tasks set is expected to become obsolete if corresponding changes are made to asyncio in Python 3.13. Fixes tornadoweb#3209 Fixes tornadoweb#3047 Fixes tornadoweb#2763 Some issues involve this warning as their most visible symptom, but have an underlying cause that should still be addressed. Updates tornadoweb#2914 Updates tornadoweb#2356
Per the warning in the asyncio documentation, we need to hold a strong reference to all asyncio Tasks to prevent premature GC. Following discussions in cpython (python/cpython#91887), we hold these references on the IOLoop instance to ensure that they are strongly held but do not cause leaks if the event loop itself is discarded. This is expected to fix all of the various "task was destroyed but it is pending" warnings that have been reported. The IOLoop._pending_tasks set is expected to become obsolete if corresponding changes are made to asyncio in Python 3.13. Fixes tornadoweb#3209 Fixes tornadoweb#3047 Fixes tornadoweb#2763 Some issues involve this warning as their most visible symptom, but have an underlying cause that should still be addressed. Updates tornadoweb#2914 Updates tornadoweb#2356 (cherry picked from commit bffed1a)
Hi, guys
My code works fine in FastAPI, but got errors below in Tornado !
ERROR:asyncio:Task was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
File "app.py", line 20, in
tornado.ioloop.IOLoop.current().start()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/home/qspace/python3.8.2/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
self._run_once()
File "/home/qspace/python3.8.2/lib/python3.8/asyncio/base_events.py", line 1851, in _run_once
handle._run()
File "/home/qspace/python3.8.2/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/ioloop.py", line 758, in _run_callback
ret = callback()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/http1connection.py", line 735, in _server_request_loop
ret = yield conn.read_response(request_delegate)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/http1connection.py", line 152, in read_response
return self._read_message(delegate)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 346, in wrapper
runner = Runner(result, future, yielded)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1080, in init
self.run()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/http1connection.py", line 238, in _read_message
delegate.finish()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/routing.py", line 256, in finish
self.delegate.finish()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/web.py", line 2195, in finish
self.execute()
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/web.py", line 2227, in execute
self.handler._execute(transforms, *self.path_args,
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 346, in wrapper
runner = Runner(result, future, yielded)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1078, in init
if self.handle_yield(first_yielded):
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1221, in handle_yield
self.future = convert_yielded(yielded)
File "/home/qspace/python3.8.2/lib/python3.8/functools.py", line 874, in wrapper
return dispatch(args[0].class)(*args, **kw)
File "/home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py", line 1361, in convert_yielded
return _wrap_awaitable(yielded)
task: <Task pending name='Task-350' coro=<MainHandler.get() running at app.py:8> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fa18ca65910>()] created at /home/qspace/python3.8.2/lib/python3.8/asyncio/base_events.py:422> cb=[IOLoop.add_future..() at /home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/ioloop.py:719] created at /home/qspace/.local/share/virtualenvs/qspace-BOV63HU7/lib/python3.8/site-packages/tornado/gen.py:1361>
The text was updated successfully, but these errors were encountered: