How do I capture SIGINT in Python on Windows?

python, signals, windows

Solution

After opening the bug upstream the root cause of the problem was found and a patch was written. This patch won't be going into the python 2.x series.

Problem

(Similar to this question) On UNIX under Python 2.7, at the Python prompt: ``` >>> import signal >>> def handler(signal, frame): ... print 'welcome to the handler' ... >>> signal.signal(signal.SIGINT, handler) <built-in function default_int_handler> ``` I press ctrl-c ``` >>> welcome to the handler >>> ``` On Windows: ``` >>> import signal >>> def handler(signal, frame): ... print 'welcome to the handler' ... >>> signal.signal(signal.SIGINT, handler) <built-in function default_int_handler> ``` Upon pressing ctrl-c: ``` >>> KeyboardInterrupt >>> ``` I can verify that `handler` is being installed Python-side as the handler for SIGINT (calling `signal.signal` a second timer returns my `handler`). How can I capture SIGINT on Windows?

Original source