3
(類似this question)如何在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
第二定時器返回我handler
)。我如何在Windows上捕獲SIGINT?
我已經在Windows Server 2008 R2上用Python 2.6.6測試了它,上面的代碼正常工作。此問題必須僅在2.7版本中。 – emigue