Commit 66b1c52d authored by Denis Bilenko's avatar Denis Bilenko

testunner.py: kill the whole process group

parent dc10d52e
...@@ -49,6 +49,11 @@ import traceback ...@@ -49,6 +49,11 @@ import traceback
from unittest import _TextTestResult, defaultTestLoader, TextTestRunner from unittest import _TextTestResult, defaultTestLoader, TextTestRunner
import platform import platform
try:
killpg = os.killpg
except AttributeError:
killpg = None
try: try:
import sqlite3 import sqlite3
except ImportError: except ImportError:
...@@ -266,31 +271,41 @@ def run_subprocess(args, options): ...@@ -266,31 +271,41 @@ def run_subprocess(args, options):
retcode = [] retcode = []
def kill():
if popen.poll() is None:
try:
popen.kill()
except Exception, ex:
log('%s: %s', popen.pid, ex)
if killpg:
try:
killpg(popen.pid, 9)
except OSError, ex:
if ex.errno != 3:
raise
def killer(): def killer():
retcode.append('TIMEOUT') retcode.append('TIMEOUT')
sys.stderr.write('Killing %s (%s) because of timeout\n' % (popen.pid, args)) sys.stderr.write('Killing %s (%s) because of timeout\n' % (popen.pid, args))
popen.kill() kill()
timeout = Timer(options.timeout, killer) timeout = Timer(options.timeout, killer)
timeout.start() timeout.start()
output = '' output = ''
output_printed = False output_printed = False
try: try:
try: if options.capture:
if options.capture: while True:
while True: data = popen.stdout.read(1)
data = popen.stdout.read(1) if not data:
if not data: break
break output += data
output += data if options.verbosity >= 2:
if options.verbosity >= 2: sys.stdout.write(data)
sys.stdout.write(data) output_printed = True
output_printed = True retcode.append(popen.wait())
retcode.append(popen.wait())
except Exception:
popen.kill()
raise
finally: finally:
kill()
timeout.cancel() timeout.cancel()
# QQQ compensating for run_tests' screw up # QQQ compensating for run_tests' screw up
module_name = args[0] module_name = args[0]
...@@ -587,6 +602,11 @@ def main(): ...@@ -587,6 +602,11 @@ def main():
options.runid = str(random.random())[2:] options.runid = str(random.random())[2:]
log('Generated runid: %s', options.runid) log('Generated runid: %s', options.runid)
if options.record: if options.record:
if killpg:
try:
os.setpgrp()
except AttributeError:
pass
run_tests(options, args) run_tests(options, args)
else: else:
spawn_subprocesses(options, args) spawn_subprocesses(options, args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment