Q: Python subprocess kill doesn't release the file handle When you start a windows executable using subprocess.Popen in shell mode and kill it (instead of letting the exe finish running), the executable remains locked for as long as the python program is running. This doesn't happen when shell=False. Anyone know a solution for this?
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)


A: You are terminating the shell and not the process it spawned. That is my guess. If that's right, have a look at this question:
subprocess: deleting child processes in Windows
