@@ -209,8 +209,7 @@ def _sendback_result(result_queue, work_id, result=None, exception=None):
209
209
result_queue .put (_ResultItem (work_id , exception = exc ))
210
210
211
211
212
- def _process_worker (call_queue , result_queue , initializer , initargs ,
213
- idle_worker_semaphore ):
212
+ def _process_worker (call_queue , result_queue , initializer , initargs ):
214
213
"""Evaluates calls from call_queue and places the results in result_queue.
215
214
216
215
This worker is run in a separate process.
@@ -222,8 +221,6 @@ def _process_worker(call_queue, result_queue, initializer, initargs,
222
221
to by the worker.
223
222
initializer: A callable initializer, or None
224
223
initargs: A tuple of args for the initializer
225
- idle_worker_semaphore: A multiprocessing.Semaphore that is used to
226
- prevent new workers from being spawned when there are idle workers.
227
224
"""
228
225
if initializer is not None :
229
226
try :
@@ -252,8 +249,6 @@ def _process_worker(call_queue, result_queue, initializer, initargs,
252
249
# open files or shared memory that is not needed anymore
253
250
del call_item
254
251
255
- # increment idle process count after worker finishes job
256
- idle_worker_semaphore .release ()
257
252
258
253
class _ExecutorManagerThread (threading .Thread ):
259
254
"""Manages the communication between this process and the worker processes.
@@ -323,6 +318,12 @@ def run(self):
323
318
# while waiting on new results.
324
319
del result_item
325
320
321
+ # attempt to increment idle process count
322
+ executor = self .executor_reference ()
323
+ if executor is not None :
324
+ executor ._idle_worker_semaphore .release ()
325
+ del executor
326
+
326
327
if self .is_shutting_down ():
327
328
self .flag_executor_shutting_down ()
328
329
@@ -656,8 +657,7 @@ def _adjust_process_count(self):
656
657
args = (self ._call_queue ,
657
658
self ._result_queue ,
658
659
self ._initializer ,
659
- self ._initargs ,
660
- self ._idle_worker_semaphore ))
660
+ self ._initargs ))
661
661
p .start ()
662
662
self ._processes [p .pid ] = p
663
663
@@ -730,7 +730,6 @@ def shutdown(self, wait=True, *, cancel_futures=False):
730
730
self ._call_queue = None
731
731
self ._result_queue = None
732
732
self ._processes = None
733
- self ._idle_worker_semaphore = None
734
733
735
734
if self ._executor_manager_thread_wakeup :
736
735
self ._executor_manager_thread_wakeup = None
0 commit comments