@@ -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
193193def 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+
209214class 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
0 commit comments