@@ -187,7 +187,7 @@ class ProgressConfig:
187
187
# progressable thing happening per source process. This is
188
188
# probably fine in practise, but there could be corner cases
189
189
# where it's not. Something to watch out for.
190
- _progress_counter = multiprocessing . Value ( "Q" , 0 )
190
+ _progress_counter = None
191
191
192
192
193
193
def update_progress (inc ):
@@ -206,18 +206,30 @@ def set_progress(value):
206
206
_progress_counter .value = value
207
207
208
208
209
+ def setup_progress_counter (counter ):
210
+ global _progress_counter
211
+ _progress_counter = counter
212
+
213
+
209
214
class ParallelWorkManager (contextlib .AbstractContextManager ):
210
215
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 )
211
221
if worker_processes <= 0 :
212
222
# NOTE: this is only for testing, not for production use!
213
223
self .executor = SynchronousExecutor ()
214
224
else :
215
225
self .executor = cf .ProcessPoolExecutor (
216
226
max_workers = worker_processes ,
227
+ mp_context = ctx ,
228
+ initializer = setup_progress_counter ,
229
+ initargs = (_progress_counter ,),
217
230
)
218
231
self .futures = set ()
219
232
220
- set_progress (0 )
221
233
if progress_config is None :
222
234
progress_config = ProgressConfig ()
223
235
self .progress_config = progress_config
0 commit comments