"lei yang" <yanglei.f...@gmail.com> wrote
def runForAWhile(cmd, secs=10):
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 status
if 0 == status:
print("'%s' is program exited" %cmd)
else:
try:
os.kill(proc.pid, signal.SIGINT)
why it print many "None" in 10 second. which means "ifconfig" is
running in 10sec, why, what's wrong withi my script,
You only check the status once *before* entering the while loop.
You need another status check inside the loop.
I just want to let my programe running, if it's timeout(10sec), kill
it
Its not clear from your mail if you have checked whether the
process really is running - using the OS commands 'top' or 'ps'
for example or whjether its just the None result you are concerned
about. But try updating status first...
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor