Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I capture SIGINT in Python on Windows?

(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?

like image 522
ldrg Avatar asked May 22 '13 08:05

ldrg


1 Answers

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.

like image 124
ldrg Avatar answered Sep 23 '22 14:09

ldrg