Skip to content

Commit cb21f5f

Browse files
authored
bpo-30131: test_logging now joins queue threads (#1298) (#1317)
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 caa59c1 commit cb21f5f

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
@@ -3163,6 +3163,7 @@ def setup_and_log(log_queue, ident):
31633163
handler.close()
31643164

31653165
@patch.object(logging.handlers.QueueListener, 'handle')
3166+
@support.reap_threads
31663167
def test_handle_called_with_queue_queue(self, mock_handle):
31673168
for i in range(self.repeat):
31683169
log_queue = queue.Queue()
@@ -3172,10 +3173,13 @@ def test_handle_called_with_queue_queue(self, mock_handle):
31723173

31733174
@support.requires_multiprocessing_queue
31743175
@patch.object(logging.handlers.QueueListener, 'handle')
3176+
@support.reap_threads
31753177
def test_handle_called_with_mp_queue(self, mock_handle):
31763178
for i in range(self.repeat):
31773179
log_queue = multiprocessing.Queue()
31783180
self.setup_and_log(log_queue, '%s_%s' % (self.id(), i))
3181+
log_queue.close()
3182+
log_queue.join_thread()
31793183
self.assertEqual(mock_handle.call_count, 5 * self.repeat,
31803184
'correct number of handled log messages')
31813185

@@ -3188,6 +3192,7 @@ def get_all_from_queue(log_queue):
31883192
return []
31893193

31903194
@support.requires_multiprocessing_queue
3195+
@support.reap_threads
31913196
def test_no_messages_in_queue_after_stop(self):
31923197
"""
31933198
Five messages are logged then the QueueListener is stopped. This
@@ -3200,6 +3205,9 @@ def test_no_messages_in_queue_after_stop(self):
32003205
self.setup_and_log(queue, '%s_%s' %(self.id(), i))
32013206
# time.sleep(1)
32023207
items = list(self.get_all_from_queue(queue))
3208+
queue.close()
3209+
queue.join_thread()
3210+
32033211
expected = [[], [logging.handlers.QueueListener._sentinel]]
32043212
self.assertIn(items, expected,
32053213
'Found unexpected messages in queue: %s' % (

0 commit comments

Comments
 (0)