使用子流程popen在长流程中获取pid

尼尔斯

我需要使用在Python 3.5.2中使用Popen运行的进程的PID。

有这个:

with open(info['stdout_file'], 'w') as logfile:
    prcs = sp.Popen(split, 
                    stdout=logfile, 
                    stderr=logfile, 
                    cwd=info['runfolder'])

streams = prcs.communicate()
out, err = streams

post = {'pid': prcs.pid}
r = requests.post('https://.../receive_status.php', data=post)

仅在过程完成后才发布过程的PID。但是我需要过程中能够杀死它。有什么办法吗?因为杀死

弗雷迪亚诺·齐格里奥(Frediano Ziglio)

该pid可以在子进程中使用。Popen返回对象,无需等待。是等待过程完成的通讯功能。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章