如何在 Windows 上的 Python 中捕获 SIGINT? [英] How do I capture SIGINT in Python on Windows?

查看:35
本文介绍了如何在 Windows 上的 Python 中捕获 SIGINT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(类似于这个问题)

在 Python 2.7 下的 UNIX 上,在 Python 提示符处:

On UNIX under Python 2.7, at the Python prompt:

 >>> 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 上:

On 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 后:

Upon pressing ctrl-c:

 >>>
 KeyboardInterrupt
 >>>

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

I can verify that handler is being installed Python-side as the handler for SIGINT (calling signal.signal a second timer returns my handler). How can I capture SIGINT on Windows?

推荐答案

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

After opening the bug upstream the root cause of the problem was found and a patch was written. This patch won't be going into the python 2.x series.

这篇关于如何在 Windows 上的 Python 中捕获 SIGINT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆