Skip to content

Keep a reference to the created task#218

Merged
insolor merged 1 commit into
insolor:mainfrom
glglgl-de:keep-task-reference
Jun 17, 2026
Merged

Keep a reference to the created task#218
insolor merged 1 commit into
insolor:mainfrom
glglgl-de:keep-task-reference

Conversation

@glglgl-de

Copy link
Copy Markdown
Contributor

The Python documentation states that asyncio only keeps a weak reference to a created task. If the caller doesn't keep it, it might be garbage collected.

Thus, keep a reference in a set. Remove that as soon as the task is done.

Besides, let the wrapper function return that task for the case that someone wants to access the return value of the wrapped function.

Comment thread async_tkinter_loop/async_tkinter_loop.py Outdated
Comment thread async_tkinter_loop/async_tkinter_loop.py Outdated
@glglgl-de glglgl-de force-pushed the keep-task-reference branch from 75a5329 to fbdcb95 Compare June 17, 2026 04:39
@insolor

insolor commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Another thing, please rename tasks to _tasks. It definitely should not be a part of public interface.

The Python documentation states that asyncio only keeps a weak reference
to a created task. If the caller doesn't keep it, it might be garbage collected.

Thus, keep a reference in a set. Remove that as soon as the task is done.

Besides, let the wrapper function return that task for the case that someone
wants to access the return value of the wrapped function.
@glglgl-de glglgl-de force-pushed the keep-task-reference branch from fbdcb95 to 6698c1f Compare June 17, 2026 06:16
@insolor insolor merged commit 2f13afb into insolor:main Jun 17, 2026
12 checks passed
@insolor

insolor commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Thanks for your contribution, much appreciated

@glglgl-de

Copy link
Copy Markdown
Contributor Author

Thanks for accepting my contribution.

@glglgl-de glglgl-de deleted the keep-task-reference branch June 17, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants