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

2021-03-03 Thread Eryk Sun
Eryk Sun added the comment: Alexander, I wrote the above sample function to be slotted directly into the existing design based on the SIGINT event. I wasn't looking to rewrite everything using user-mode APCs and alertable waits. A change like that could have ramifications for applications th

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

2021-03-03 Thread Alexander Grigoriev
Alexander Grigoriev 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 asynchron

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

2021-03-02 Thread Eryk Sun
Eryk Sun added the comment: > But on this particular issue, making the unconditional wait be > interruptable by signals shouldn't be impossible. PyThread_acquire_lock_timed() in Python/thread_nt.h currently ignores intr_flag. The current implementation calls EnterNonRecursiveMutex(), which i

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

2019-02-08 Thread Steve Dower
Steve Dower added the comment: I'm not sure it's quite as simple as calling sys.exit, but it would be a great project to bring universal cancellation support to all (regularly) blocking functions. Asyncio has suffered from this as well. Part of the problem is that POSIX APIs often don't supp

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

2019-02-07 Thread Eryk Sun
Eryk Sun added the comment: Python's C signal handler sets a flag and returns, and the signal is eventually handled in the main thread. In Windows, this means the Python SIGINT handler won't be called so long as the main thread is blocked. (In Unix the signal is delivered on the main thread

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

2019-02-07 Thread Chris Billington
Chris Billington added the comment: If I add: import signal signal.signal(signal.SIGINT, signal.SIG_DFL) before the wait() call, then the call is interruptible on both Python versions without needing to add a timeout. -- ___ Python tracker

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

2019-02-07 Thread Chris Billington
New submission from Chris Billington : I'm experiencing that the following short program: import threading event = threading.Event() event.wait() Cannot be interrupted with Ctrl-C on Python 2.7.15 or 3.7.1 on Windows 10 (using the Anaconda Python distribution). However, if the wait is given