Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66e2fb6

Browse files
committed
Issue #12364: Fix a hang in concurrent.futures.ProcessPoolExecutor.
1 parent 645a0dd commit 66e2fb6

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ def shutdown_one_process():
213213
work_item.future.set_exception(result_item.exception)
214214
else:
215215
work_item.future.set_result(result_item.result)
216-
continue
217-
# If we come here, we either got a timeout or were explicitly woken up.
218-
# In either case, check whether we should start shutting down.
216+
# Check whether we should start shutting down.
219217
executor = executor_reference()
220218
# No more work items can be added if:
221219
# - The interpreter is shutting down OR
@@ -234,9 +232,6 @@ def shutdown_one_process():
234232
p.join()
235233
call_queue.close()
236234
return
237-
else:
238-
# Start shutting down by telling a process it can exit.
239-
shutdown_one_process()
240235
del executor
241236

242237
_system_limits_checked = False

Lib/test/test_concurrent_futures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ def test_interpreter_shutdown(self):
109109
self.assertFalse(err)
110110
self.assertEqual(out.strip(), b"apple")
111111

112+
def test_hang_issue12364(self):
113+
fs = [self.executor.submit(time.sleep, 0.1) for _ in range(50)]
114+
self.executor.shutdown()
115+
for f in fs:
116+
f.result()
117+
112118

113119
class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest):
114120
def _prime_executor(self):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Core and Builtins
9797
Library
9898
-------
9999

100+
- Issue #12364: Fix a hang in concurrent.futures.ProcessPoolExecutor.
101+
The hang would occur when retrieving the result of a scheduled future after
102+
the executor had been shut down.
103+
100104
- Issue #13502: threading: Fix a race condition in Event.wait() that made it
101105
return False when the event was set and cleared right after.
102106

0 commit comments

Comments
 (0)