14
14
from http .server import BaseHTTPRequestHandler , HTTPServer
15
15
from json import dumps , load , loads
16
16
from multiprocessing import get_context
17
+ from multiprocessing .sharedctypes import Value
17
18
from threading import Thread
18
19
from urllib .parse import parse_qs , urlparse , urlunparse
19
20
20
21
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
29
34
30
35
31
36
class Context :
@@ -39,10 +44,14 @@ def reset(self, method='forkserver'):
39
44
self .mp_context .set_forkserver_preload (self .module_names )
40
45
41
46
def submit (self , fn , * args , ** kwargs ):
47
+ exitcode = Value ('i' , - 1 , lock = False )
48
+ args = (exitcode , ) + args
42
49
child = self .mp_context .Process (target = fn , args = args , kwargs = kwargs )
43
50
child .start ()
44
51
child .join ()
45
- return child .exitcode
52
+ if child .exitcode :
53
+ logging .info ('child process failed with %d' , child .exitcode )
54
+ return exitcode .value
46
55
47
56
48
57
class HTTPRequestHandler (BaseHTTPRequestHandler ):
0 commit comments