Skip to content

Add: helper to keep strong references to created tasks#12

Merged
TrueBrain merged 1 commit intoOpenTTD:mainfrom
TrueBrain:asyncio-task-helper
Feb 19, 2023
Merged

Add: helper to keep strong references to created tasks#12
TrueBrain merged 1 commit intoOpenTTD:mainfrom
TrueBrain:asyncio-task-helper

Conversation

@TrueBrain
Copy link
Copy Markdown
Member

Python's asyncio.create_task() keeps an internal weak reference. In result, the GC can remove the task if the returning task is not tracked.

But it is much more convenient to use that function as a fire&forget, and to not always have to track it.

So, instead of having to add code in other places to send these tasks to a background-queue, take over the whole factory and create a strong reference for every task created.

Python's asyncio.create_task() keeps an internal weak reference.
In result, the GC can remove the task if the returning task is
not tracked.

But it is much more convenient to use that function as a
fire&forget, and to not always have to track it.

So, instead of having to add code in other places to send these
tasks to a background-queue, take over the whole factory and
create a strong reference for every task created.
@TrueBrain TrueBrain merged commit 286194b into OpenTTD:main Feb 19, 2023
@TrueBrain TrueBrain deleted the asyncio-task-helper branch February 19, 2023 15:35
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