How to Kill a Process on Windows from Within Python

Kill a process in Windows 10 from the PyCharm command line

Updated Answer:

Essentially this problem is caused by temporary files not being deleted, as I found here. The solution for this is to type import tempfile and tempfile.gettempdir() into the console to return the path to the temporary file directory. Copy and paste this into the file explorer and navigate into the .tensorboard-info folder and delete anything inside. This will clear all the processes tensorboard thinks it is running, which should stop the issue from happening.

The reason this issue is happening is that if tensorboard closes unexpectedly it leaves behind temporary files that should have been cleaned up after the process stops. Because of this any new tensorboard process checks the temp folder and finds a file which indicates that another instance is running, even though it no longer is.

Kill external process started by batch file on Windows from within Python script

I managed to solve the issue by running the subprocess.call("taskkill /F /im process.exe").

I am not sure why os.system didn't work in the first place, perhaps it's due to its outdated nature. Hopefully, it helps those who will encounter a similar issue!



Related Topics



Leave a reply



Submit