GraiaProject / BroadcastControl

a high performance, highly customizable, elegantly designed event system based on asyncio
32 stars 7 forks source link

fix: prevent undone task be killed by gc #48

Closed ProgramRipper closed 2 years ago

ProgramRipper commented 2 years ago

根据 https://github.com/python/cpython/issues/91887 中描述的问题, asyncio 只会保留未完成的 Task 的弱引用. 所以, 不能使用 "free-flying tasks" 的形式.

本 pr 使用了 https://docs.python.org/zh-cn/3/library/asyncio-task.html#asyncio.create_task 中提供的解决方案

ProgramRipper commented 2 years ago

我将会长期跟踪 https://github.com/python/cpython/issues/91887 的后续处理结果. 如果未来的 asyncio 如该 issue 所建议的那样, 更改为保持对 Task 的强引用, 我将会移除此更改.