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
Title: ProactorEventLoop ignores Ctrl+C after closing unrelated loop
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, mhils, yselivanov
Priority: normal Keywords:

Created on 2022-03-14 17:14 by mhils, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
proactor-repro.py mhils, 2022-03-14 17:14
Messages (2)
msg415169 - (view) Author: Maximilian Hils (mhils) * Date: 2022-03-14 17:14
When a (second) ProactorEventLoop is garbage-collected, the current ProactorEventLoop starts to ignore Ctrl+C on Windows until it is woken up. The attached repro shows a minimal example. Uncommenting the `create_task` call or not using a second event loop fixes the behavior.

I couldn't find any shared/global objects in asyncio/windows_events.py, so I'm not sure what is causing this, or why the wakeup task helps.

FWIW, the second event loop in our code base originated from a stray `get_event_loop()` call, one more example that speaks in favor of `get_running_loop()`!
msg415200 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-14 22:01
Ctrl-C handling is added by #23057

It uses signal.set_wakeup_fd() https://github.com/asvetlov/cpython/blob/main/Lib/asyncio/proactor_events.py#L631-L634

So, the last event loop steals Ctrl+C handling.
Not sure if we can improve it.
Running two concurrent loops in the same thread is a bad idea for many reasons. Ctrl+C is not the only reason.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91170
2022-03-23 21:49:14asvetlovsetstatus: open -> closed
resolution: wont fix
stage: resolved
2022-03-14 22:01:02asvetlovsetmessages: + msg415200
2022-03-14 17:14:48mhilscreate