Skip to content

Instantly share code, notes, and snippets.

@International
Created September 9, 2011 12:06
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save International/1206050 to your computer and use it in GitHub Desktop.
Save International/1206050 to your computer and use it in GitHub Desktop.
python subprocess pid/kill example
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()
@Chriss4123
Copy link

very good very helpful i died

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment