我可以将 SIGINT 发送到 Windows 上的 Python 子进程吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1095549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:47:06  来源:igfitidea点击:

Can I send SIGINT to a Python subprocess on Windows?

pythonwindowssubprocesssigintsignal-handling

提问by Ryan

I've got a Python script managing a gdb process on Windows, and I need to be able to send a SIGINT to the spawned process in order to halt the target process (managed by gdb)

我有一个在 Windows 上管理 gdb 进程的 Python 脚本,我需要能够向生成的进程发送一个 SIGINT 以停止目标进程(由 gdb 管理)

It appears that there is only SIGTERM available in Win32, but clearly if I run gdb from the console and Ctrl+C, it thinks it's receiving a SIGINT. Is there a way I can fake this such that the functionality is available on all platforms?

似乎在 Win32 中只有 SIGTERM 可用,但很明显,如果我从控制台和 Ctrl+C 运行 gdb,它认为它正在接收 SIGINT。有没有办法可以伪造这个功能,以便在所有平台上都可以使用该功能?

(I am using the subprocess module, and python 2.5/2.6)

(我正在使用 subprocess 模块和 python 2.5/2.6)

回答by drudru

Windows doesn't have the unix signals IPC mechanism.

Windows 没有 unix 信号 IPC 机制。

I would look at sending a CTRL-C to the gdb process.

我会考虑向 gdb 进程发送一个 CTRL-C。