我有一个主进程分叉了一些子进程。我希望能够在我的主进程获得终止信号时关闭这些子进程。理想情况下,我想要做一些沿线:Python在关闭主进程时关闭孩子
def handler(signum, frame, pid_list):
log('Killing Process')
for pid in pid_list:
os.kill(pid, signal.SIGTERM)
os.waitpid(pid, 0) # need
sys.exit()
if __name__ == "__main__":
<code that creates child processes, pids>
signal.signal(signal.SIGTERM, handler(pid_list))
但当然,这不工作......任何建议?
嗨J.F.,感谢关于pip'ing多处理器的指针;我没有打算在Centos上安装Python 2.6,但这可能只是一个窍门。我明天会放弃它并给你一些反馈。 –
伟大的名字句柄,顺便说一句 –
好的,所以这个效果很好,其他人尝试这样做的一些指针:1. p.daemon需要与signal.signal配对,p.daemon不只是做它的拥有。 2.在Centos上安装多处理:yum install python-pip gcc python-devel && pip-python install multiprocessing。再次感谢J.F. –