When I am running a Python script, I sometime get the error that:
"the process cannot access the file, because it is being used by another process"
Now I am wondering: Is there a way in python to:
os.system('taskkill /f /im PROCESS.exe) )You can try iterating over processes and kill it if you match the file needed with psutil:
import psutil
for p in psutil.process_iter():
try:
if "filename" in str(p.open_files()):
print(p.name())
print("^^^^^^^^^^^^^^^^^")
p.kill()
except:
continue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With