mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-10 20:29:10 +01:00
Kill process trees on timeouts (os.killpg)
This commit is contained in:
parent
afe6862525
commit
9f14c9dda0
@ -334,9 +334,8 @@ class Context(ctx):
|
||||
cargs = {}
|
||||
if 'timeout' in kw:
|
||||
cargs['timeout'] = kw['timeout']
|
||||
if kw['timeout'] is not None:
|
||||
if kw['shell']:
|
||||
Logs.warn('Shell commands cannot timeout %r', cmd)
|
||||
if not 'start_new_session' in kw:
|
||||
kw['start_new_session'] = True
|
||||
del kw['timeout']
|
||||
if 'input' in kw:
|
||||
if kw['input']:
|
||||
@ -420,9 +419,8 @@ class Context(ctx):
|
||||
cargs = {}
|
||||
if 'timeout' in kw:
|
||||
cargs['timeout'] = kw['timeout']
|
||||
if kw['timeout'] is not None:
|
||||
if kw['shell']:
|
||||
Logs.warn('Shell commands cannot timeout %r', cmd)
|
||||
if not 'start_new_session' in kw:
|
||||
kw['start_new_session'] = True
|
||||
del kw['timeout']
|
||||
if 'input' in kw:
|
||||
if kw['input']:
|
||||
|
@ -9,7 +9,7 @@ The portability fixes try to provide a consistent behavior of the Waf API
|
||||
through Python versions 2.5 to 3.X and across different platforms (win32, linux, etc)
|
||||
"""
|
||||
|
||||
import os, sys, errno, traceback, inspect, re, datetime, platform, base64
|
||||
import os, sys, errno, traceback, inspect, re, datetime, platform, base64, signal
|
||||
try:
|
||||
import cPickle
|
||||
except ImportError:
|
||||
@ -865,6 +865,9 @@ def run_regular_process(cmd, kwargs, cargs={}):
|
||||
try:
|
||||
out, err = proc.communicate(**cargs)
|
||||
except TimeoutExpired:
|
||||
try:
|
||||
os.killpg(proc.pid, signal.SIGKILL)
|
||||
except AttributeError:
|
||||
proc.kill()
|
||||
out, err = proc.communicate()
|
||||
raise TimeoutExpired(proc.args, timeout=cargs['timeout'], output=out, stderr=err)
|
||||
@ -874,6 +877,9 @@ def run_regular_process(cmd, kwargs, cargs={}):
|
||||
try:
|
||||
status = proc.wait(**cargs)
|
||||
except TimeoutExpired as e:
|
||||
try:
|
||||
os.killpg(proc.pid, signal.SIGKILL)
|
||||
except AttributeError:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
raise e
|
||||
|
@ -2,7 +2,7 @@
|
||||
# encoding: utf-8
|
||||
# Thomas Nagy, 2016 (ita)
|
||||
|
||||
import sys, traceback, base64
|
||||
import os, sys, traceback, base64, signal
|
||||
try:
|
||||
import cPickle
|
||||
except ImportError:
|
||||
@ -34,6 +34,9 @@ def run():
|
||||
try:
|
||||
out, err = proc.communicate(**cargs)
|
||||
except TimeoutExpired:
|
||||
try:
|
||||
os.killpg(proc.pid, signal.SIGKILL)
|
||||
except AttributeError:
|
||||
proc.kill()
|
||||
out, err = proc.communicate()
|
||||
raise TimeoutExpired(proc.args, timeout=cargs['timeout'], output=out, stderr=err)
|
||||
|
Loading…
Reference in New Issue
Block a user