如何杀死在 Windows 中使用 subprocess.pOpen() 打开的这个 python 进程?

问题描述

以下用于终止使用 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。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)