Description
Feature
Hi there,
I wanted to suggest adding a rule to MyPy to help detect a potential bug that can occur when using asyncio.create_task
. If a developer doesn't hold a reference to the task object returned by create_task
, the task may disappear without warning when Python runs garbage collection. This can lead to unpredictable failures in the code, which can be extremely difficult to debug.
References:
https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/
https://news.ycombinator.com/item?id=34754276
Pitch
I think adding a rule to MyPy that flags code which creates an asyncio task but doesn't hold a reference to it would be very helpful in preventing this bug from occurring. It would alert developers to the fact that they need to make sure they're holding a reference to the task object if they want to avoid this problem.