Skip to content

Commit c912bc3

Browse files
encukouvstinnerserhiy-storchaka
authored
[3.12] gh-114440: Close writer pipe in multiprocessing.Queue, not concurrent.futures (GH-114489)
This was left out of the 3.12 backport for three related issues: - gh-107219 (which adds `self.call_queue._writer.close()` to `_ExecutorManagerThread` in `concurrent.futures`) - gh-109370 (which changes this to be only called on Windows) - gh-109047 (which moves the call to `multiprocessing.Queue`'s `_terminate_broken`) Without this change, ProcessPoolExecutor sometimes hangs on Windows when a worker process is terminated. Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 03f8f77 commit c912bc3

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Lib/concurrent/futures/process.py

-5
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,6 @@ def _terminate_broken(self, cause):
524524

525525
self.call_queue._terminate_broken()
526526

527-
# gh-107219: Close the connection writer which can unblock
528-
# Queue._feed() if it was stuck in send_bytes().
529-
if sys.platform == 'win32':
530-
self.call_queue._writer.close()
531-
532527
# clean up resources
533528
self._join_executor_internals(broken=True)
534529

Lib/multiprocessing/queues.py

+5
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ def _terminate_broken(self):
164164
# gh-94777: Prevent queue writing to a pipe which is no longer read.
165165
self._reader.close()
166166

167+
# gh-107219: Close the connection writer which can unblock
168+
# Queue._feed() if it was stuck in send_bytes().
169+
if sys.platform == 'win32':
170+
self._writer.close()
171+
167172
self.close()
168173
self.join_thread()
169174

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
On Windows, closing the connection writer when cleaning up a broken
2+
:class:`multiprocessing.Queue` queue is now done for all queues, rather than
3+
only in :mod:`concurrent.futures` manager thread.
4+
This can prevent a deadlock when a ``multiprocessing`` worker process terminates
5+
without cleaning up.
6+
This completes the backport of patches by Victor Stinner and Serhiy Storchaka.

0 commit comments

Comments
 (0)