Skip to content

Commit 3b69d91

Browse files
authored
bpo-30886: Fix multiprocessing.Queue.join_thread() (#2642)
multiprocessing.Queue.join_thread() now waits until the thread completes, even if the thread was started by the same process which created the queue. Fix the following warning which occurs randomly when running test_handle_called_with_mp_queue of test_logging.QueueListenerTest: Warning -- threading_cleanup() failed to cleanup -1 threads after 4 sec (count: 0, dangling: 1)
1 parent 7e60192 commit 3b69d91

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

Lib/multiprocessing/queues.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,7 @@ def _start_thread(self):
169169
self._thread.start()
170170
debug('... done self._thread.start()')
171171

172-
# On process exit we will wait for data to be flushed to pipe.
173-
#
174-
# However, if this process created the queue then all
175-
# processes which use the queue will be descendants of this
176-
# process. Therefore waiting for the queue to be flushed
177-
# is pointless once all the child processes have been joined.
178-
created_by_this_process = (self._opid == os.getpid())
179-
if not self._joincancelled and not created_by_this_process:
172+
if not self._joincancelled:
180173
self._jointhread = Finalize(
181174
self._thread, Queue._finalize_join,
182175
[weakref.ref(self._thread)],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix multiprocessing.Queue.join_thread(): it now waits until the thread
2+
completes, even if the thread was started by the same process which created
3+
the queue.

0 commit comments

Comments
 (0)