Skip to content

Commit c5e0b4d

Browse files
Explicitly use spawn multiprocessing context
Closes #175 Closes #201
1 parent 65ad5cf commit c5e0b4d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bio2zarr/core.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class ProgressConfig:
187187
# progressable thing happening per source process. This is
188188
# probably fine in practise, but there could be corner cases
189189
# where it's not. Something to watch out for.
190-
_progress_counter = multiprocessing.Value("Q", 0)
190+
_progress_counter = None
191191

192192

193193
def update_progress(inc):
@@ -206,18 +206,30 @@ def set_progress(value):
206206
_progress_counter.value = value
207207

208208

209+
def setup_progress_counter(counter):
210+
global _progress_counter
211+
_progress_counter = counter
212+
213+
209214
class ParallelWorkManager(contextlib.AbstractContextManager):
210215
def __init__(self, worker_processes=1, progress_config=None):
216+
# Need to specify this explicitly to suppport Macs and
217+
# for future proofing.
218+
ctx = multiprocessing.get_context("spawn")
219+
global _progress_counter
220+
_progress_counter = ctx.Value("Q", 0)
211221
if worker_processes <= 0:
212222
# NOTE: this is only for testing, not for production use!
213223
self.executor = SynchronousExecutor()
214224
else:
215225
self.executor = cf.ProcessPoolExecutor(
216226
max_workers=worker_processes,
227+
mp_context=ctx,
228+
initializer=setup_progress_counter,
229+
initargs=(_progress_counter,),
217230
)
218231
self.futures = set()
219232

220-
set_progress(0)
221233
if progress_config is None:
222234
progress_config = ProgressConfig()
223235
self.progress_config = progress_config

tests/test_core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def test_bad_min_max(self, min_value, max_value):
5656
core.min_int_dtype(min_value, max_value)
5757

5858

59-
@pytest.mark.skipif(sys.platform == "darwin", reason="Issue #75")
6059
class TestParallelWorkManager:
6160
@pytest.mark.parametrize("total", [1, 10, 2**63])
6261
@pytest.mark.parametrize("workers", [0, 1])

0 commit comments

Comments
 (0)