summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorJyn Spring 琴春 <me@vx.st>2022-09-07 14:35:06 +0700
committerGitHub <noreply@github.com>2022-09-07 09:35:06 +0200
commit5e9ec76a20062ec8bb7ee0c936be28c63837b6dd (patch)
treee6d78a8215e2f627d568548d6e34e22e073a0481 /numpy/lib
parent7a17d01977e5e6a9b7ef8f4c435235e711bc97be (diff)
downloadnumpy-5e9ec76a20062ec8bb7ee0c936be28c63837b6dd.tar.gz
TST,BUG: Us context from spawn to fork in (#22204)
Since Python 3.8, the default start method for multiprocessing has been changed from fork to spawn on macOS The default start method is still fork on other Unix platforms[1], causing inconsistency on memory sharing model It will cause a memory-sharing problem for the test test_large_zip on macOS as the memory sharing model between spawn and fork is different The fix Change the start method for this test back to fork under this testcase context In this test case context, the bug that caused default start method changed to spawn for macOS will not be triggered It is context limited, so this change will not affect default start method other than test_large_zip All platforms have the same memory sharing model now After the change, test_large_zip is passed on macOS https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods Closes gh-22203
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test_io.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 38a751d11..dde48ccae 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -13,7 +13,7 @@ from tempfile import NamedTemporaryFile
from io import BytesIO, StringIO
from datetime import datetime
import locale
-from multiprocessing import Process, Value
+from multiprocessing import Value, get_context
from ctypes import c_bool
import numpy as np
@@ -595,7 +595,12 @@ class TestSaveTxt:
# Use an object in shared memory to re-raise the MemoryError exception
# in our process if needed, see gh-16889
memoryerror_raised = Value(c_bool)
- p = Process(target=check_large_zip, args=(memoryerror_raised,))
+
+ # Since Python 3.8, the default start method for multiprocessing has
+ # been changed from 'fork' to 'spawn' on macOS, causing inconsistency
+ # on memory sharing model, lead to failed test for check_large_zip
+ ctx = get_context('fork')
+ p = ctx.Process(target=check_large_zip, args=(memoryerror_raised,))
p.start()
p.join()
if memoryerror_raised.value: