加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 22:33:57 所属栏目:Windows 来源:网络整理
导读:(与 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
(与 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,handler)
 <built-in function default_int_handler>

按ctrl-c:

>>>
 KeyboardInterrupt
 >>>

我可以验证处理程序是否正在安装Python端作为SIGINT的处理程序(调用signal.signal第二个计时器返回我的处理程序).如何在Windows上捕获SIGINT?

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读