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:
return p
if not timeout:
stdout, _ = p.communicate()
return p.poll(), stdout
if timeout:
while timeout > 0 and p.poll() is None:
timeout = timeout - timeinterval
time.sleep(timeinterval)
if p.poll() is None:
p.kill()
return p.poll(), 'Run timeout'
while timeout > 0 and p.poll() is None:
timeout = timeout - timeinterval
time.sleep(timeinterval)
if p.poll() is None:
p.kill()
return p.poll(), 'Run timeout'
stdout, _ = p.communicate()
return p.poll(), stdout