为什么 multiprocessing.Process 没有 send_signal 方法?
Why multiprocessing.Process doesn't have a send_signal method?
与 subprocess.Popen 不同,multiprocessing.Process 没有 send_signal 方法。为什么?是否有推荐的方法将 SIGINT 等信号发送到 multiprocessing.Process?我应该为此目的使用 os.kill() 吗?提前致谢。
你的第一个问题很有道理。
我 认为 那是因为 multiprocessing
和 subprocess
库有不同的设计目标(正如 this answer) : the former is for making multiple Python scripts cooperate over different CPUs for achieving a common task, while the latter is for integrating external programs in your Python program. Because IPC (inter-process communication) is far easier between cooperating Python multiprocesses (there are queues and pipes 所解释的,你可以将 Python 对象作为arguments, ...) 而不是我们只能假定遵守 OS 接口的外部程序(文本 stdin
/stdout
, should 正确处理信号,...)。
因此,与另一个多进程通信的默认方式不是 OS 信号,因此认为集成它没有用。
还要记住 (C)Python 是开源的,所以你可以自己贡献这个集成。
关于你的第二个问题,已经有答案了(cf How can I send a signal from a python program?),是的:
use os.kill()
与 subprocess.Popen 不同,multiprocessing.Process 没有 send_signal 方法。为什么?是否有推荐的方法将 SIGINT 等信号发送到 multiprocessing.Process?我应该为此目的使用 os.kill() 吗?提前致谢。
你的第一个问题很有道理。
我 认为 那是因为 multiprocessing
和 subprocess
库有不同的设计目标(正如 this answer) : the former is for making multiple Python scripts cooperate over different CPUs for achieving a common task, while the latter is for integrating external programs in your Python program. Because IPC (inter-process communication) is far easier between cooperating Python multiprocesses (there are queues and pipes 所解释的,你可以将 Python 对象作为arguments, ...) 而不是我们只能假定遵守 OS 接口的外部程序(文本 stdin
/stdout
, should 正确处理信号,...)。
因此,与另一个多进程通信的默认方式不是 OS 信号,因此认为集成它没有用。
还要记住 (C)Python 是开源的,所以你可以自己贡献这个集成。
关于你的第二个问题,已经有答案了(cf How can I send a signal from a python program?),是的:
use
os.kill()