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="ping 128.224.165.20 -c 4"
runForAWhile(cmd,30)
Why "status' is aways !=0, ----> the program is NOT exit?
Lei