You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shield() documentation should mention user needs to keep reference to the task #94972
asyncio will only keep weak references to alive tasks (in _all_tasks). If a user does not keep a reference to a task and the task is not currently executing or sleeping, the user may get "Task was destroyed but it is pending!".
changed the title [-]sheild() documentation should mention user needs to keep reference to the task[/-][+]shield() documentation should mention user needs to keep reference to the task[/+]on Jul 18, 2022
closed!
Traceback (most recent call last):
File "/home/graingert/projects/foo.py", line 14, in async_fn
await asyncio.get_running_loop().create_future()
GeneratorExit
Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<async_fn() done, defined at /home/graingert/projects/foo.py:12> wait_for=<Future pending cb=[Task.task_wakeup()]>>
None
======================
closed!
Traceback (most recent call last):
File "/home/graingert/projects/foo.py", line 14, in async_fn
await asyncio.get_running_loop().create_future()
GeneratorExit
Task was destroyed but it is pending!
task: <Task pending name='Task-6' coro=<async_fn() done, defined at /home/graingert/projects/foo.py:12> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Activity
[-]sheild() documentation should mention user needs to keep reference to the task[/-][+]shield() documentation should mention user needs to keep reference to the task[/+]kumaraditya303 commentedon Jul 22, 2022
Can you provide reproducible code where this happens?
graingert commentedon Jul 22, 2022
See also #93297
graingert commentedon Jul 22, 2022
@kumaraditya303 here's the repro on python3.10:
output:
gvanrossum commentedon Aug 24, 2022
Are you too busy to submit a PR that updates the docs?
graingert commentedon Aug 24, 2022
There's one linked here #94973
gvanrossum commentedon Aug 29, 2022
I think I get the same output on 3.11. Question, is
import objgraphneeded in the repro? (I had to delete it, no idea what it is.)gh-94972: document that shield users need to keep a reference to thei…
pythongh-94972: document that shield users need to keep a reference t…
pythongh-94972: document that shield users need to keep a reference t…
gh-94972: document that shield users need to keep a reference to thei…
gh-94972: document that shield users need to keep a reference to thei…
graingert commentedon Sep 12, 2022
Left in by accident. It's not needed to cause the error but I used it to help build it
Keep reference to background tasks.