Skip to content

Commit 2d491f6

Browse files
ligurioTotktonada
andcommitted
python3: set 'fork' start method
In Python 3 start method 'spawn' in multiprocessing module becomes default on Mac OS [1]. The 'spawn' method causes re-execution of some code, which is already executed in the main process. At least it is seen on the lib/__init__.py code, which removes the 'var' directory. Some other code may have side effects too, it requires investigation. The method also requires object serialization that doesn't work when objects use lambdas, whose for example used in class TestSuite (lib/test_suite.py). The latter problem is easy to fix, but the former looks more fundamental. So we stick to the 'fork' method now. The new 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 Co-authored-by: Alexander Turenko <[email protected]>
1 parent e9e8bee commit 2d491f6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test-run.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from lib import Options
5757
from lib.colorer import color_stdout
5858
from lib.utils import print_tail_n
59+
from lib.utils import PY3
5960
from lib.worker import get_task_groups
6061
from lib.worker import get_reproduce_file
6162
from lib.worker import reproduce_task_groups
@@ -218,6 +219,23 @@ def main_consistent():
218219

219220

220221
if __name__ == "__main__":
222+
# In Python 3 start method 'spawn' in multiprocessing module becomes
223+
# default on Mac OS.
224+
#
225+
# The 'spawn' method causes re-execution of some code, which is already
226+
# executed in the main process. At least it is seen on the
227+
# lib/__init__.py code, which removes the 'var' directory. Some other
228+
# code may have side effects too, it requires investigation.
229+
#
230+
# The method also requires object serialization that doesn't work when
231+
# objects use lambdas, whose for example used in class TestSuite
232+
# (lib/test_suite.py).
233+
#
234+
# The latter problem is easy to fix, but the former looks more
235+
# fundamental. So we stick to the 'fork' method now.
236+
if PY3:
237+
multiprocessing.set_start_method('fork')
238+
221239
# don't sure why, but it values 1 or 2 gives 1.5x speedup for parallel
222240
# test-run (and almost doesn't affect consistent test-run)
223241
os.environ['OMP_NUM_THREADS'] = '2'

0 commit comments

Comments
 (0)