如何在Windows上的Python中捕获SIGINT?


问题内容

(类似于这个问题

在UNIX上的Python 2.7下,在Python提示符下:

 >>> import signal
 >>> def handler(signal, frame):
 ...     print 'welcome to the handler'
 ...
 >>> signal.signal(signal.SIGINT, handler)
 <built-in function default_int_handler>

我按ctrl-c

 >>> welcome to the handler

 >>>

在Windows上:

 >>> import signal
 >>> def handler(signal, frame):
 ...     print 'welcome to the handler'
 ...
 >>> signal.signal(signal.SIGINT, handler)
 <built-in function default_int_handler>

在按ctrl-c时:

 >>>
 KeyboardInterrupt
 >>>

我可以验证是否handler已在python端将其安装为SIGINT的处理程序(调用signal.signal第二个计时器将返回my
handler)。如何在Windows上捕获SIGINT?


问题答案:

在上游打开错误后,找到了问题的根本原因,并编写了补丁。该补丁不会进入python
2.x系列。