You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ProactorEventLoop ignores Ctrl+C after closing unrelated loop #91170
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()!
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.
Activity
mhils commentedon Mar 14, 2022
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_taskcall 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 ofget_running_loop()!asvetlov commentedon Mar 14, 2022
Ctrl-C handling is added by bpo-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.