Allow applications to handle KeyboardInterrupt
- 主要语言
- Python
- 星标
- 2.5k
- 派生
- 260
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 17
描述
Currently the behavior between trio vs asyncio/curio differs in how ctrl+c is handled. Trio raises `KeyboardInterrupt` in the main task while asyncio and curio just clean up the tasks and exit. It would be preferable to unify the behavior across all backends so that at least applications using `anyio.run()` as their entry point could take advantage of this.
For asyncio and curio, this probably requires setting up a signal handler and raising the `KeyboardInterrupt` exception there. This will be particularly tricky on asyncio which, unlike curio, does not allow specific exceptions to be directly raised on tasks. It may require hijacking the coroutine object of the main task, much like what I did in [asyncio_extras](https://github.com/agronholm/asyncio_extras/blob/master/asyncio_extras/threads.py).
贡献指南
评估
这个 Issue 还没有评估数据。