Skip to content

Commit 4581ed3

Browse files
committed
Kill the child instead of letting it die
1 parent 901b250 commit 4581ed3

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

pyfrc/test_support/pytest_dist_plugin.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import multiprocessing
2+
import os
23
import pathlib
34
import sys
5+
import time
46

57
from typing import Type
68

@@ -34,7 +36,7 @@ def _enable_faulthandler():
3436

3537
faulthandler.enable()
3638
except Exception as e:
37-
logger.warn("Could not enable faulthandler: %s", e)
39+
logger.warning("Could not enable faulthandler: %s", e)
3840
return
3941

4042
try:
@@ -46,15 +48,25 @@ def _enable_faulthandler():
4648
return
4749

4850

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):
5052
"""This function runs in a subprocess"""
5153
robotpy.logconfig.configure_logging(verbose)
5254
_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+
5360
ec = pytest.main(
5461
[item_nodeid, "--no-header", *config_args],
55-
plugins=[PyFrcPlugin(robot_class, robot_file, True)],
62+
plugins=[plugin],
5663
)
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)
5870

5971

6072
def _run_test_in_new_process(
@@ -69,16 +81,21 @@ def _run_test_in_new_process(
6981
else:
7082
item_nodeid = test_function.nodeid
7183

84+
parent, child = multiprocessing.Pipe()
85+
7286
process = multiprocessing.Process(
7387
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),
7589
)
7690
process.start()
77-
process.join()
91+
try:
92+
ec = parent.recv()
93+
finally:
94+
process.kill()
7895

79-
if process.exitcode != 0:
96+
if ec != 0:
8097
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})",
8299
pytrace=False,
83100
)
84101

0 commit comments

Comments
 (0)