-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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 created by StreamReaderProtocol gets garbage collected. #90467
Comments
Documentation states that a reference must be kept when creating a task, https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task. This is not done in StreamReaderProtocol, https://github.com/python/cpython/blob/main/Lib/asyncio/streams.py#L244. I've provided a simple example to force garbage collection of this task which results in Am I missing something or using the library incorrectly? I've followed the examples at https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-server-using-streams. |
Thanks for the bug report. Seems like your analysis is correct. Could you make a pull request which adds a task reference? |
I'm removing 3.7 and 3.8 from the "versions" field, since those branches are old enough that they're now only accepting security-related patches. |
As a workaround, it's possible to keep the reference in a global variable background_tasks = set()
def create_connection_task(*args, **kwargs):
task = asyncio.create_task(handle_connection(*args, **kwargs))
background_tasks.add(task)
task.add_done_callback(background_tasks.discard)
# asyncio.start_server(create_connection_task, ..) |
…d task (pythonGH-96323) (cherry picked from commit e860e52) Co-authored-by: Kirill <[email protected]>
…d task (pythonGH-96323) (cherry picked from commit e860e52) Co-authored-by: Kirill <[email protected]>
…GH-96323) (#96344) (cherry picked from commit e860e52) Co-authored-by: Kirill <[email protected]> Co-authored-by: Kirill <[email protected]>
…GH-96323) (cherry picked from commit e860e52) Co-authored-by: Kirill <[email protected]>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: