modify run method

This commit is contained in:
agnewee 2017-12-08 23:33:04 +08:00
parent 4beaa525d5
commit f715b37153
1 changed files with 7 additions and 9 deletions

View File

@ -10,16 +10,14 @@ def run(cmd, wait=True, shell=True, timeout=0, timeinterval=1):
if not wait: if not wait:
return p return p
if not timeout: if timeout:
stdout, _ = p.communicate()
return p.poll(), stdout
while timeout > 0 and p.poll() is None: while timeout > 0 and p.poll() is None:
timeout = timeout - timeinterval timeout = timeout - timeinterval
time.sleep(timeinterval) time.sleep(timeinterval)
if p.poll() is None: if p.poll() is None:
p.kill() p.kill()
return p.poll(), 'Run timeout' return p.poll(), 'Run timeout'
stdout, _ = p.communicate() stdout, _ = p.communicate()
return p.poll(), stdout return p.poll(), stdout