Skip to content

Commit 8ca2f2f

Browse files
authored
bpo-30131: test_logging now joins queue threads (python#1298)
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).
1 parent 6e67695 commit 8ca2f2f

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
@@ -3184,6 +3184,7 @@ def setup_and_log(log_queue, ident):
31843184
handler.close()
31853185

31863186
@patch.object(logging.handlers.QueueListener, 'handle')
3187+
@support.reap_threads
31873188
def test_handle_called_with_queue_queue(self, mock_handle):
31883189
for i in range(self.repeat):
31893190
log_queue = queue.Queue()
@@ -3193,10 +3194,13 @@ def test_handle_called_with_queue_queue(self, mock_handle):
31933194

31943195
@support.requires_multiprocessing_queue
31953196
@patch.object(logging.handlers.QueueListener, 'handle')
3197+
@support.reap_threads
31963198
def test_handle_called_with_mp_queue(self, mock_handle):
31973199
for i in range(self.repeat):
31983200
log_queue = multiprocessing.Queue()
31993201
self.setup_and_log(log_queue, '%s_%s' % (self.id(), i))
3202+
log_queue.close()
3203+
log_queue.join_thread()
32003204
self.assertEqual(mock_handle.call_count, 5 * self.repeat,
32013205
'correct number of handled log messages')
32023206

@@ -3209,6 +3213,7 @@ def get_all_from_queue(log_queue):
32093213
return []
32103214

32113215
@support.requires_multiprocessing_queue
3216+
@support.reap_threads
32123217
def test_no_messages_in_queue_after_stop(self):
32133218
"""
32143219
Five messages are logged then the QueueListener is stopped. This
@@ -3221,6 +3226,9 @@ def test_no_messages_in_queue_after_stop(self):
32213226
self.setup_and_log(queue, '%s_%s' %(self.id(), i))
32223227
# time.sleep(1)
32233228
items = list(self.get_all_from_queue(queue))
3229+
queue.close()
3230+
queue.join_thread()
3231+
32243232
expected = [[], [logging.handlers.QueueListener._sentinel]]
32253233
self.assertIn(items, expected,
32263234
'Found unexpected messages in queue: %s' % (

0 commit comments

Comments
 (0)