【发布时间】:2013-05-22 08:02:24
【问题描述】:
(类似于this question)
在 Python 2.7 下的 UNIX 上,在 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 第二个计时器返回我的 handler)。如何在 Windows 上捕获 SIGINT?
【问题讨论】:
-
我已经在 Windows Server 2008 R2 上使用 Python 2.6.6 对其进行了测试,上面的代码可以正常工作。这个问题一定是2.7版本才有的。