python subprocess kill example

A little something for me, so that I can remember in the future how to kill a process started via Popen.

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
    if proc.poll() is None:
        print "Killing process %s with pid %s " % (to_run,proc.pid)


0 Responses to “python subprocess kill example”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats

  • 229,426 hits

%d bloggers like this: