➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: asyncio should make it easy to enable cooperative SIGINT handling
类型: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.7
process
状态: open Resolution:
Dependencies: 29988 31388 后续:
分配给: 抄送列表: aeros, giampaolo.rodola, gregory.p.smith, ncoghlan, njs, ryanhiebert, vstinner, yselivanov
优先级: normal 关键字:

ncoghlan 于 2017-09-07 19:37 创建。最近一次由 admin 于 2022-04-11 14:58 修改。

Messages (4)
msg301619 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) 日期: 2017-09-07 19:37
Issue 29988 covers the fact that with the default SIGINT handler installed, a poorly timed Ctrl-C can lead to context managers failing to even start running their __(a)exit__ methods, let alone complete them.

For the asynchronous case, the problem is even worse, as the *event loop* may be interrupted at arbitrary points if the default SIGINT handler is left in place.

To handle this robustly, it's desirable to make it easy to switch event-driven programs over to cooperative Ctrl-C handling by installing an asyncio SIGINT handler while the event loop is running, rather than leaving the default SIGINT handler in place.

(Note: while installing a cooperative SIGINT handler will enable more robust event-loop managed resource cleanup, it will have the downside that Ctrl-C won't be able to interrupt a coroutine that has incorrectly blocked the main thread)
msg301631 - (view) Author: Nathaniel Smith (njs) * (Python committer) 日期: 2017-09-07 21:22
Some prior discussion on the old asyncio tracker:
    https://github.com/python/asyncio/pull/305#issuecomment-168714572
    https://github.com/python/asyncio/issues/341
msg301661 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) 日期: 2017-09-08 01:04
Issue 31388 is also potentially relevant here, as registering a signal handler for SIGINT isn't sufficient to cover all potential cases were Py_AddPendingCall gets called. In particular, the tests for issue 29988 use Py_AddPendingCall to emulate Ctrl-C, rather than relying on SIGINT actually being raised.
msg301669 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) 日期: 2017-09-08 02:28
As per Nathaniel's comments on issue 29988 and 31388, doing this robustly relies on:

1. the event loop being able to reliably guard itself and __aexit__ method implementations against interrupts (issue 31388)
2. "async with" statements ensuring that if the frame resumes after calling __aenter__, then it will also call __aexit__ (as was done for synchronous with statements in issue 29988)
历史
日期 用户 动作 参数
2022-04-11 14:58:52admin修改github: 75568
2019-10-14 23:11:16aeros修改抄送: + aeros
2019-09-07 12:32:21ryanhiebert修改抄送: + ryanhiebert
2017-09-08 02:28:12ncoghlan修改dependencies: + with statements are not ensuring that __exit__ is called if __enter__ succeeds, Provide a way to defer SIGINT handling in the current thread
消息: + msg301669
2017-09-08 01:04:35ncoghlan修改消息: + msg301661
2017-09-07 21:22:41njs修改消息: + msg301631
2017-09-07 19:37:30ncoghlan创建