[英]How to kill this python process opened using subprocess.pOpen() in Windows?
下面用于终止使用 subprocess.Popen subprocess.Popen()
打开的进程的代码适用于 Linux。
import os
import signal
import subprocess
# The os.setsid() is passed in the argument preexec_fn so
# it's run after the fork() and before exec() to run the shell.
pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,
shell=True, preexec_fn=os.setsid)
os.killpg(os.getpgid(pro.pid), signal.SIGTERM) # Send the signal to all the process groups
不幸的是,它在 Windows 上不起作用。该进程拒绝被杀死。 如何修改代码,使进程可以在 Windows 上被杀死?
我在 Anaconda 上使用 Windows 10、Python 3.8。
使用 subprocess.Popen.terminate subprocess.Popen.terminate()
终止子进程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.