mirror of https://gitlab.com/ita1024/waf.git
Python3 - Kill processes in subprocess timeouts #1807
This commit is contained in:
parent
f7367c8051
commit
fdc3b47067
|
@ -24,6 +24,12 @@ if os.name == 'posix' and sys.version_info[0] < 3:
|
||||||
else:
|
else:
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
try:
|
||||||
|
TimeoutExpired = subprocess.TimeoutExpired
|
||||||
|
except AttributeError:
|
||||||
|
class TimeoutExpired(object):
|
||||||
|
pass
|
||||||
|
|
||||||
from collections import deque, defaultdict
|
from collections import deque, defaultdict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -856,11 +862,19 @@ def run_regular_process(cmd, kwargs, cargs={}):
|
||||||
"""
|
"""
|
||||||
proc = subprocess.Popen(cmd, **kwargs)
|
proc = subprocess.Popen(cmd, **kwargs)
|
||||||
if kwargs.get('stdout') or kwargs.get('stderr'):
|
if kwargs.get('stdout') or kwargs.get('stderr'):
|
||||||
out, err = proc.communicate(**cargs)
|
try:
|
||||||
|
out, err = proc.communicate(**cargs)
|
||||||
|
except TimeoutExpired:
|
||||||
|
proc.kill()
|
||||||
|
out, err = proc.communicate(**cargs)
|
||||||
status = proc.returncode
|
status = proc.returncode
|
||||||
else:
|
else:
|
||||||
out, err = (None, None)
|
out, err = (None, None)
|
||||||
status = proc.wait(**cargs)
|
try:
|
||||||
|
status = proc.wait(**cargs)
|
||||||
|
except TimeoutExpired:
|
||||||
|
proc.kill()
|
||||||
|
status = proc.wait(**cargs)
|
||||||
return status, out, err
|
return status, out, err
|
||||||
|
|
||||||
def run_process(cmd, kwargs, cargs={}):
|
def run_process(cmd, kwargs, cargs={}):
|
||||||
|
|
|
@ -13,6 +13,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
try:
|
||||||
|
TimeoutExpired = subprocess.TimeoutExpired
|
||||||
|
except AttributeError:
|
||||||
|
class TimeoutExpired(object):
|
||||||
|
pass
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
txt = sys.stdin.readline().strip()
|
txt = sys.stdin.readline().strip()
|
||||||
if not txt:
|
if not txt:
|
||||||
|
@ -25,7 +31,11 @@ def run():
|
||||||
out, err, ex, trace = (None, None, None, None)
|
out, err, ex, trace = (None, None, None, None)
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(cmd, **kwargs)
|
proc = subprocess.Popen(cmd, **kwargs)
|
||||||
out, err = proc.communicate(**cargs)
|
try:
|
||||||
|
out, err = proc.communicate(**cargs)
|
||||||
|
except TimeoutExpired:
|
||||||
|
proc.kill()
|
||||||
|
out, err = proc.communicate(**cargs)
|
||||||
ret = proc.returncode
|
ret = proc.returncode
|
||||||
except (OSError, ValueError, Exception) as e:
|
except (OSError, ValueError, Exception) as e:
|
||||||
exc_type, exc_value, tb = sys.exc_info()
|
exc_type, exc_value, tb = sys.exc_info()
|
||||||
|
|
Loading…
Reference in New Issue