@@ -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 ):
@@ -201,23 +201,30 @@ def get_progress():
201
201
return val
202
202
203
203
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
207
207
208
208
209
209
class ParallelWorkManager (contextlib .AbstractContextManager ):
210
210
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 )
211
216
if worker_processes <= 0 :
212
217
# NOTE: this is only for testing, not for production use!
213
218
self .executor = SynchronousExecutor ()
214
219
else :
215
220
self .executor = cf .ProcessPoolExecutor (
216
221
max_workers = worker_processes ,
222
+ mp_context = ctx ,
223
+ initializer = setup_progress_counter ,
224
+ initargs = (_progress_counter ,),
217
225
)
218
226
self .futures = set ()
219
227
220
- set_progress (0 )
221
228
if progress_config is None :
222
229
progress_config = ProgressConfig ()
223
230
self .progress_config = progress_config
@@ -258,16 +265,6 @@ def submit(self, *args, **kwargs):
258
265
self .futures .add (future )
259
266
return future
260
267
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
-
271
268
def results_as_completed (self ):
272
269
for future in cf .as_completed (self .futures ):
273
270
yield future .result ()
0 commit comments