Skip to content

Instantly share code, notes, and snippets.

@sweenzor
Created December 16, 2011 05:06
Show Gist options
  • Save sweenzor/1484573 to your computer and use it in GitHub Desktop.
Save sweenzor/1484573 to your computer and use it in GitHub Desktop.
Experimenting with subprocess control
#!/usr/bin/env python
import time
import subprocess
from syslog import syslog
def run():
#cmd = ['ifconfig']
cmd = ['ping', '-c', '3', 'google.com']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
mark = time.time()
while (time.time()-mark) < 200:
syslog(p.stdout.readline())
if p.poll() is not None:
break
try:
p.kill()
print 'killed'
except:
print 'done'
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment