Skip to content

Commit 6459284

Browse files
committed
Fix result position for killed workers, add Steve suggested change to use dict.pop().
1 parent e1a9eb5 commit 6459284

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/multiprocessing/pool.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,13 @@ def _join_exited_workers(pool, outqueue, job_assignments):
299299
pid = worker.ident
300300
worker.join()
301301
cleaned = True
302-
if pid in job_assignments:
302+
job_info = job_assignments.pop(pid, None)
303+
if job_info is not None:
303304
# If the worker process died without communicating back
304305
# while running a job, add a default result for it.
305-
job = job_assignments[pid]
306-
outqueue.put((job, i, (False, RuntimeError("Worker died"))))
307-
del job_assignments[pid]
306+
outqueue.put(
307+
(*job_info, (False, RuntimeError("Worker died")))
308+
)
308309
del pool[i]
309310
return cleaned
310311

@@ -602,7 +603,7 @@ def _handle_results(outqueue, get, cache, job_assignments):
602603
# task_info is True or False when a task has completed but
603604
# None indicates information about which process has
604605
# accepted a job from the queue.
605-
job_assignments[value] = job
606+
job_assignments[value] = (job, i)
606607
else:
607608
try:
608609
cache[job]._set(i, (task_info, value))
@@ -623,7 +624,7 @@ def _handle_results(outqueue, get, cache, job_assignments):
623624

624625
job, i, (task_info, value) = task
625626
if task_info is None:
626-
job_assignments[value] = job
627+
job_assignments[value] = (job, i)
627628
else:
628629
try:
629630
cache[job]._set(i, (task_info, value))

0 commit comments

Comments
 (0)