[issue35935] threading.Event().wait() not interruptable with Ctrl-C on Windows

Alexander Grigoriev report at bugs.python.org
Wed Mar 3 11:15:32 EST 2021


Alexander Grigoriev <alegrigoriev at gmail.com> added the comment:

@ericsun:

Windows calls the console event handler in a separate thread. The console event handler receives CTRL_C_EVENT, CTRL_BREAK_EVENT, console close, logoff, system shutdown events.

Originally, Windows devised an APC mechanism to simulate asynchronous delivery of Posix signal to threads. Those APCs are invoked during alertable wait functions. Delivery of an APS also aborts the wait with WAIT_IO_COMPLETION return code.

An APC can be queued by QueueUserAPC function.

An APC queue can be processed at any time by calling an alertable wait function with zero timeout, for example SleepEx(0, TRUE).

If you need an APC to break wait for asynchronous input (like console or serial port), use overlapped I/O with GetOverlappedResultEx function. To cancel the I/O request, use CancelIo function on the thread which issued the request. Note that you still need to wait for the cancelled request to complete the cancellation with GetOverlappedResult.

----------
nosy: +alegrigoriev

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35935>
_______________________________________


More information about the Python-bugs-list mailing list