1
1
import multiprocessing
2
+ import os
2
3
import pathlib
3
4
import sys
5
+ import time
4
6
5
7
from typing import Type
6
8
@@ -34,7 +36,7 @@ def _enable_faulthandler():
34
36
35
37
faulthandler .enable ()
36
38
except Exception as e :
37
- logger .warn ("Could not enable faulthandler: %s" , e )
39
+ logger .warning ("Could not enable faulthandler: %s" , e )
38
40
return
39
41
40
42
try :
@@ -46,15 +48,25 @@ def _enable_faulthandler():
46
48
return
47
49
48
50
49
- def _run_test (item_nodeid , config_args , robot_class , robot_file , verbose ):
51
+ def _run_test (item_nodeid , config_args , robot_class , robot_file , verbose , pipe ):
50
52
"""This function runs in a subprocess"""
51
53
robotpy .logconfig .configure_logging (verbose )
52
54
_enable_faulthandler ()
55
+
56
+ # keep the plugin around because it has a reference to the robot
57
+ # and we don't want it to die and deadlock
58
+ plugin = PyFrcPlugin (robot_class , robot_file , True )
59
+
53
60
ec = pytest .main (
54
61
[item_nodeid , "--no-header" , * config_args ],
55
- plugins = [PyFrcPlugin ( robot_class , robot_file , True ) ],
62
+ plugins = [plugin ],
56
63
)
57
- sys .exit (ec )
64
+
65
+ # Don't let the process die, let the parent kill us to avoid
66
+ # python interpreter badness
67
+ pipe .send (ec )
68
+ while True :
69
+ time .sleep (100 )
58
70
59
71
60
72
def _run_test_in_new_process (
@@ -69,16 +81,21 @@ def _run_test_in_new_process(
69
81
else :
70
82
item_nodeid = test_function .nodeid
71
83
84
+ parent , child = multiprocessing .Pipe ()
85
+
72
86
process = multiprocessing .Process (
73
87
target = _run_test ,
74
- args = (item_nodeid , config_args , robot_class , robot_file , verbose ),
88
+ args = (item_nodeid , config_args , robot_class , robot_file , verbose , child ),
75
89
)
76
90
process .start ()
77
- process .join ()
91
+ try :
92
+ ec = parent .recv ()
93
+ finally :
94
+ process .kill ()
78
95
79
- if process . exitcode != 0 :
96
+ if ec != 0 :
80
97
pytest .fail (
81
- f"Test failed in subprocess: { item_nodeid } (exit code { process . exitcode } )" ,
98
+ f"Test failed in subprocess: { item_nodeid } (exit code { ec } )" ,
82
99
pytrace = False ,
83
100
)
84
101
0 commit comments