I have a simple script that calls another python script as a subprocess. I can confirm the subprocess is started and I can grab its PID.
When I attempt to terminate the subprocess (in win), I get the SUCCESS message against the correct PID, but Windows task manager shows the 2nd python.exe process to still be running.
Any suggestions to accomplish this task in Win? I'll be extending this to also work in OSX and Linux eventually:
#!/usr/bin/env python import os, sys import subprocess from subprocess import Popen, PIPE, STDOUT, check_call pyTivoPath="c:\pyTivo\pyTivo.py" print "\nmyPID: %d" % os.getpid() ## Start pyTivo ## py_process = subprocess.Popen(pyTivoPath, shell=True, stdout=PIPE, stderr=subprocess.STDOUT) print "newPID: %s" % py_process.pid ## Terminate pyTivo ## #py_process.terminate() - for nonWin (?) py_kill = subprocess.Popen("TASKKILL /PID "+ str(py_process.pid) + " /f") raw_input("\nPress Enter to continue...")
Note: Python2.7 required, psutils not available