2013-05-22 26 views
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?

+2

我已經在Windows Server 2008 R2上用Python 2.6.6測試了它,上面的代碼正常工作。此問題必須僅在2.7版本中。 – emigue

回答

8

在上游打開the bug後,發現問題的根本原因並編寫了補丁程序。這個補丁不會進入python 2.x系列。

相關問題