@@ -346,12 +346,29 @@ def run(self):
346346 self .terminate_broken (cause )
347347 return
348348 if result_item is not None :
349- self .process_result_item (result_item )
350349 exit_pid = result_item .exit_pid
350+ work_id = result_item .work_id
351+ exception = result_item .exeption
352+ result = result_item .result
353+ del result_item
354+ # Process the received a result_item. This can be either the PID of a
355+ # worker that exited gracefully or a _ResultItem
356+
357+ # Received a _ResultItem so mark the future as completed.
358+ work_item = self .pending_work_items .pop (work_id , None )
359+ # work_item can be None if another process terminated (see above)
360+ if work_item is not None :
361+ f = work_item .future
362+ del work_item
363+ if exception :
364+ f .set_exception (exception )
365+ else :
366+ f .set_result (result )
367+ del f
351368
352- # Delete reference to result_item to avoid keeping references
369+ # Delete reference to exception/result to avoid keeping references
353370 # while waiting on new results.
354- del result_item
371+ del exception , result
355372
356373 process_exited = exit_pid is not None
357374 if process_exited :
@@ -435,19 +452,6 @@ def wait_result_broken_or_wakeup(self):
435452
436453 return result_item , is_broken , cause
437454
438- def process_result_item (self , result_item ):
439- # Process the received a result_item. This can be either the PID of a
440- # worker that exited gracefully or a _ResultItem
441-
442- # Received a _ResultItem so mark the future as completed.
443- work_item = self .pending_work_items .pop (result_item .work_id , None )
444- # work_item can be None if another process terminated (see above)
445- if work_item is not None :
446- if result_item .exception :
447- work_item .future .set_exception (result_item .exception )
448- else :
449- work_item .future .set_result (result_item .result )
450-
451455 def is_shutting_down (self ):
452456 # Check whether we should start shutting down the executor.
453457 executor = self .executor_reference ()
0 commit comments