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).
via https://github.com/Zac-HD/flake8-async-archive/issues/5: the docs for asyncio.create_task say:
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 ofasyncio.create_task
,loop.run_until_complete
, etc, but on balance think it's better to have documentation explaining why you should useanyio.TaskGroup
instead (e.g. better cancellation semantics as part of structured concurrency).