[Tutor] why "ifconfig" is alway running?
lei yang
yanglei.fage at gmail.com
Sat Dec 18 17:23:37 CET 2010
my script is
#!/usr/bin/env python
import datetime
import subprocess
import sys
import os
import signal
from time import sleep
def runForAWhile(cmd, secs=10):
print("running %s" % cmd)
timeout = datetime.timedelta(seconds=secs)
print timeout
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
status = proc.poll()
start = datetime.datetime.now()
while (status is None and (datetime.datetime.now() - start) <
timeout): #not timed out
#print proc.stdout.readline() #TODO timestamp?
print status
#print datetime.datetime.now() - start
if 0 == status:
print("'%s' is program exited" %cmd)
else:
try:
os.kill(proc.pid, signal.SIGINT)
print "Process timeout: '%s'" % cmd
except OSError:
pass
cmd="ifconfig"
runForAWhile(cmd,10)
why it print many "None" in 10 second. which means "ifconfig" is
running in 10sec, why, what's wrong withi my script,
I just want to let my programe running, if it's timeout(10sec), kill it
Lei
More information about the Tutor
mailing list