@@ -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 ):
@@ -201,23 +201,30 @@ def get_progress():
201201 return val
202202
203203
204- def set_progress ( value ):
205- with _progress_counter . get_lock ():
206- _progress_counter . value = value
204+ def setup_progress_counter ( counter ):
205+ global _progress_counter
206+ _progress_counter = counter
207207
208208
209209class ParallelWorkManager (contextlib .AbstractContextManager ):
210210 def __init__ (self , worker_processes = 1 , progress_config = None ):
211+ # Need to specify this explicitly to suppport Macs and
212+ # for future proofing.
213+ ctx = multiprocessing .get_context ("spawn" )
214+ global _progress_counter
215+ _progress_counter = ctx .Value ("Q" , 0 )
211216 if worker_processes <= 0 :
212217 # NOTE: this is only for testing, not for production use!
213218 self .executor = SynchronousExecutor ()
214219 else :
215220 self .executor = cf .ProcessPoolExecutor (
216221 max_workers = worker_processes ,
222+ mp_context = ctx ,
223+ initializer = setup_progress_counter ,
224+ initargs = (_progress_counter ,),
217225 )
218226 self .futures = set ()
219227
220- set_progress (0 )
221228 if progress_config is None :
222229 progress_config = ProgressConfig ()
223230 self .progress_config = progress_config
@@ -258,16 +265,6 @@ def submit(self, *args, **kwargs):
258265 self .futures .add (future )
259266 return future
260267
261- def wait_for_completed (self , timeout = None ):
262- done , not_done = cf .wait (self .futures , timeout , cf .FIRST_COMPLETED )
263- for future in done :
264- exception = future .exception ()
265- # TODO do the check for BrokenProcessPool here
266- if exception is not None :
267- raise exception
268- self .futures = not_done
269- return done
270-
271268 def results_as_completed (self ):
272269 for future in cf .as_completed (self .futures ):
273270 yield future .result ()
0 commit comments