python-3.x - 在子进程打开的长进程中获取 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。但是我需要它在这个过程中才能杀死它。有什么办法吗?因为杀了
解决方案
pid 在 subprocess.Popen 返回对象后立即可用,无需等待。是等待进程完成的通信函数。
推荐阅读
- mysql - docker create a new image 无法启动mysql服务
- ios - 如何替换字符“。” 当焦点在 Xamarin 表单(iOS)上的输入字段时,键盘上的“,”?
- hyperledger-fabric - 背书节点如何拒绝在超级账本结构中背书?如何设计链码来实现它?
- excel - VBA MsgBox 是/否
- pdf - 如何为 PDF 设置多个密码
- python - python搜索字典值并打印
- django - 同一台 Unix 服务器上的 Django Web/Dev
- javascript - NodeJS 请求正文返回空 {}
- python - 传输数据以创建新数据框以重新构建数据框
- jasmine - compileComponents 的 Angular 4 Jasmine 问题