遵循如何终止使用 shell=True 启动的 python 子进程的建议
我有一个过程,我从以下开始
process = subprocess.Popen(my_cmd, shell=True, executable='/bin/bash', preexec_fn=os.setsid)
Run Code Online (Sandbox Code Playgroud)
my_cmd 的形式为 some_cmd_that_periodically_outputs_to_stdout | grep "some_fancy_regex" > some_output_file.txt
我用以下命令终止进程
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
Run Code Online (Sandbox Code Playgroud)
杀死后,我收到以下警告
ResourceWarning: subprocess XXX is still running
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此警告?
| 归档时间: |
|
| 查看次数: |
2858 次 |
| 最近记录: |