Skip to content

Commit d855e53

Browse files
authored
bpo-30131: test_logging now joins queue threads (#1298) (#1318)
QueueListenerTest of test_logging now closes the multiprocessing Queue and joins its thread to prevent leaking dangling threads to following tests. Add also @support.reap_threads to detect earlier if a test leaks threads (and try to "cleanup" these threads). (cherry picked from commit 8ca2f2f)
1 parent 0eda2d4 commit d855e53

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/test_logging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,6 +3067,7 @@ def setup_and_log(log_queue, ident):
30673067
handler.close()
30683068

30693069
@patch.object(logging.handlers.QueueListener, 'handle')
3070+
@support.reap_threads
30703071
def test_handle_called_with_queue_queue(self, mock_handle):
30713072
for i in range(self.repeat):
30723073
log_queue = queue.Queue()
@@ -3076,10 +3077,13 @@ def test_handle_called_with_queue_queue(self, mock_handle):
30763077

30773078
@support.requires_multiprocessing_queue
30783079
@patch.object(logging.handlers.QueueListener, 'handle')
3080+
@support.reap_threads
30793081
def test_handle_called_with_mp_queue(self, mock_handle):
30803082
for i in range(self.repeat):
30813083
log_queue = multiprocessing.Queue()
30823084
self.setup_and_log(log_queue, '%s_%s' % (self.id(), i))
3085+
log_queue.close()
3086+
log_queue.join_thread()
30833087
self.assertEqual(mock_handle.call_count, 5 * self.repeat,
30843088
'correct number of handled log messages')
30853089

@@ -3092,6 +3096,7 @@ def get_all_from_queue(log_queue):
30923096
return []
30933097

30943098
@support.requires_multiprocessing_queue
3099+
@support.reap_threads
30953100
def test_no_messages_in_queue_after_stop(self):
30963101
"""
30973102
Five messages are logged then the QueueListener is stopped. This
@@ -3104,6 +3109,9 @@ def test_no_messages_in_queue_after_stop(self):
31043109
self.setup_and_log(queue, '%s_%s' %(self.id(), i))
31053110
# time.sleep(1)
31063111
items = list(self.get_all_from_queue(queue))
3112+
queue.close()
3113+
queue.join_thread()
3114+
31073115
expected = [[], [logging.handlers.QueueListener._sentinel]]
31083116
self.assertIn(items, expected,
31093117
'Found unexpected messages in queue: %s' % (

0 commit comments

Comments
 (0)