Skip to content

Commit f4fc259

Browse files
committed
python3: set 'fork' start method
In Python 3 start method 'spawn' in multiprocessing module becomes default on Mac OS [1]. However 'spawn' method requires object serialization that doesn't work when objects use lambdas, whose for example used in class TestSuite (lib/test_suite.py). So this method is not acceptable for using with test-run. To workaround it can be possible to force fork mode with multiprocessing.set_start_method('fork'). Start method is available on Python 3 only: Traceback (most recent call last): File "../../test/test-run.py", line 227, in <module> multiprocessing.set_start_method('fork') AttributeError: 'module' object has no attribute 'set_start_method' 1. https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods. Fixes #265 Part of #20
1 parent 7b09214 commit f4fc259

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test-run.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
from lib import Options
5757
from lib.colorer import color_stdout
58-
from lib.utils import print_tail_n
58+
from lib.utils import print_tail_n, PY3
5959
from lib.worker import get_task_groups
6060
from lib.worker import get_reproduce_file
6161
from lib.worker import reproduce_task_groups
@@ -218,6 +218,15 @@ def main_consistent():
218218

219219

220220
if __name__ == "__main__":
221+
# In Python 3 start method 'spawn' in multiprocessing module becomes
222+
# default on Mac OS [1]. However 'spawn' method requires object serialization
223+
# that doesn't work when objects use lambdas, whose for example used in
224+
# class TestSuite (lib/test_suite.py). So this method is not acceptable
225+
# for using with test-run. To workaround it can be possible to force
226+
# fork mode with multiprocessing.set_start_method('fork').
227+
if PY3:
228+
multiprocessing.set_start_method('fork')
229+
221230
# don't sure why, but it values 1 or 2 gives 1.5x speedup for parallel
222231
# test-run (and almost doesn't affect consistent test-run)
223232
os.environ['OMP_NUM_THREADS'] = '2'

0 commit comments

Comments
 (0)