8000 gh-114706: Allow QueueListener.stop() to be called more than once. (G… · python/cpython@e21754d · GitHub
[go: up one dir, main page]

Skip to content

Commit e21754d

Browse files
authored
gh-114706: Allow QueueListener.stop() to be called more than once. (GH-114748)
1 parent ea30a28 commit e21754d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/logging/handlers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ def stop(self):
15861586
Note that if you don't call this before your application exits, there
15871587
may be some records still left on the queue, which won't be processed.
15881588
"""
1589-
self.enqueue_sentinel()
1590-
self._thread.join()
1591-
self._thread = None
1589+
if self._thread: # see gh-114706 - allow calling this more than once
1590+
self.enqueue_sentinel()
1591+
self._thread.join()
1592+
self._thread = None

Lib/test/test_logging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,7 @@ def test_queue_listener(self):
40894089
self.que_logger.critical(self.next_message())
40904090
finally:
40914091
listener.stop()
4092+
listener.stop() # gh-114706 - ensure no crash if called again
40924093
self.assertTrue(handler.matches(levelno=logging.WARNING, message='1'))
40934094
self.assertTrue(handler.matches(levelno=logging.ERROR, message='2'))
40944095
self.assertTrue(handler.matches(levelno=logging.CRITICAL, message='3'))

0 commit comments

Comments
 (0)
0