Skip to content

Commit ca17219

Browse files
committed
Fix returning exit code from subprocess
1 parent 27ee504 commit ca17219

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

ltest.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414
from http.server import BaseHTTPRequestHandler, HTTPServer
1515
from json import dumps, load, loads
1616
from multiprocessing import get_context
17+
from multiprocessing.sharedctypes import Value
1718
from threading import Thread
1819
from urllib.parse import parse_qs, urlparse, urlunparse
1920

2021

21-
def run_pytest(args):
22-
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
23-
level=logging.INFO)
24-
logging.info('run pytest in in-process mode: %s', args)
25-
import pytest
26-
code = pytest.main(args)
27-
logging.info('exit code is %s', code)
28-
return code
22+
def run_pytest(retcode: Value, args):
23+
try:
24+
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
25+
level=logging.INFO)
26+
logging.info('run pytest in in-process mode: %s', args)
27+
import pytest
28+
code = pytest.main(args)
29+
logging.info('pytest exit code is %s', code)
30+
retcode.value = code.value
31+
except Exception:
32+
logging.exception('failed to execute pytest in-process')
33+
raise
2934

3035

3136
class Context:
@@ -39,10 +44,14 @@ def reset(self, method='forkserver'):
3944
self.mp_context.set_forkserver_preload(self.module_names)
4045

4146
def submit(self, fn, *args, **kwargs):
47+
exitcode = Value('i', -1, lock=False)
48+
args = (exitcode, ) + args
4249
child = self.mp_context.Process(target=fn, args=args, kwargs=kwargs)
4350
child.start()
4451
child.join()
45-
return child.exitcode
52+
if child.exitcode:
53+
logging.info('child process failed with %d', child.exitcode)
54+
return exitcode.value
4655

4756

4857
class HTTPRequestHandler(BaseHTTPRequestHandler):

0 commit comments

Comments
 (0)