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
In the official asyncio documentation, I read that you have to keep a strong reference of a task in order for it not to be garbage collected. However, I noticed that the current_app.add_background_task method adds the resulting task to a weak set so it seems that it only keeps a weak reference and it does not return the task so I cannot keep a strong reference myself. But I have tested it and it seems that there are still some strong references until the task finishes which keeps it from being collected. How does it work? Where are the strong reference kept?
Can I rely on the task not being collected before it finishes running?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
In the official asyncio documentation, I read that you have to keep a strong reference of a task in order for it not to be garbage collected. However, I noticed that the
current_app.add_background_task
method adds the resulting task to a weak set so it seems that it only keeps a weak reference and it does not return the task so I cannot keep a strong reference myself. But I have tested it and it seems that there are still some strong references until the task finishes which keeps it from being collected. How does it work? Where are the strong reference kept?Can I rely on the task not being collected before it finishes running?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions