Python 子进程杀死后不释放文件句柄
当你在使用subprocess.Popen以shell模式启动一个Windows可执行文件时,如果你强行结束这个程序(而不是等它自己运行完),那么这个可执行文件会在你的Python程序运行期间一直被锁住。换句话说,你不能再运行这个程序,直到你的Python程序结束。这种情况在shell=False的时候就不会发生。有没有人知道怎么解决这个问题?
import time
import subprocess
proc = subprocess.Popen(r"path_to_executable", shell=True)
time.sleep(1)
proc.terminate() #or kill()
proc = None
# the executable will be locked for the next 100 secs
time.sleep(100)