如何在Windows上用Python捕获SIGINT?

2024-04-25 18:51:28 发布

您现在位置:Python中文网/ 问答频道 /正文

(类似于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

^{pr2}$

在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是否作为SIGINT的处理程序安装在Python端(调用signal.signal第二个计时器返回myhandler)。如何在Windows上捕获SIGINT?在


Tags: thetoinimportdefaultsignaldeffunction

热门问题