Created
September 9, 2011 12:06
-
-
Save International/1206050 to your computer and use it in GitHub Desktop.
python subprocess pid/kill example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
exit("need an argument") | |
to_run = sys.argv[1] | |
proc = subprocess.Popen(to_run) | |
print "start process with pid %s" % proc.pid | |
time.sleep(50) | |
# kill after 50 seconds if process didn't finish | |
if proc.poll() is None: | |
print "Killing process %s with pid %s " % (to_run,proc.pid) | |
proc.kill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good very helpful i died