Skip to content
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

Checks for asyncio.create_task() #207

Open
Zac-HD opened this issue Feb 23, 2024 · 0 comments
Open

Checks for asyncio.create_task() #207

Zac-HD opened this issue Feb 23, 2024 · 0 comments

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Feb 23, 2024

via Zac-HD/flake8-async-archive#5: the docs for asyncio.create_task say:

Save a reference to the result of this function, to avoid a task disappearing mid-execution. The event loop only keeps weak references to tasks. A task that isn’t referenced elsewhere may get garbage collected at any time, even before it’s done.

It's really easy to miss this and try to fire-and-forget. It would be great if flake8-async detected this.


I also wonder whether we should have an optional check which recommends using TaskGroup instead of asyncio.create_task, loop.run_until_complete, etc, but on balance think it's better to have documentation explaining why you should use anyio.TaskGroup instead (e.g. better cancellation semantics as part of structured concurrency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants