使用子进程 popen 在长进程中获取 pid
Get pid during long process with subprocess popen
我需要 运行 在 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 只有在进程完成后才会发布。但是我需要during进程才能杀掉。有什么办法吗?因为杀死
一旦 subprocess.Popen returns 对象就可以获得 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 只有在进程完成后才会发布。但是我需要during进程才能杀掉。有什么办法吗?因为杀死
一旦 subprocess.Popen returns 对象就可以获得 pid,无需等待。 是等待进程完成的通讯功能。