【问题标题】:Get pid during long process with subprocess popen在子进程打开的长进程中获取 pid
【发布时间】:2018-12-07 14:37:17
【问题描述】:

我需要来自我在 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。但我需要它的过程中能够杀死是。有什么办法吗?因为杀了

【问题讨论】:

    标签: python-3.x popen pid


    【解决方案1】:

    只要 subprocess.Popen 返回对象,pid 就可用,无需等待。 是等待进程完成的通信函数。

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 2011-12-20
      • 1970-01-01
      • 2012-03-16
      • 2017-03-23
      • 1970-01-01
      • 2017-10-11
      • 2021-05-14
      相关资源
      最近更新 更多