https://github.com/python/cpython/commit/e21754d7f8336d4647e28f355d8a3dbd5a2c7545
commit: e21754d7f8336d4647e28f355d8a3dbd5a2c7545
branch: main
author: Vinay Sajip <[email protected]>
committer: vsajip <[email protected]>
date: 2024-01-30T12:34:18Z
summary:
gh-114706: Allow QueueListener.stop() to be called more than once. (GH-114748)
files:
M Lib/logging/handlers.py
M Lib/test/test_logging.py
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 9840b7b0aeba88..e7f1322e4ba3d9 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1586,6 +1586,7 @@ def stop(self):
Note that if you don't call this before your application exits, there
may be some records still left on the queue, which won't be processed.
"""
- self.enqueue_sentinel()
- self._thread.join()
- self._thread = None
+ if self._thread: # see gh-114706 - allow calling this more than once
+ self.enqueue_sentinel()
+ self._thread.join()
+ self._thread = None
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 908e242b85f5e7..888523227c2ac4 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4089,6 +4089,7 @@ def test_queue_listener(self):
self.que_logger.critical(self.next_message())
finally:
listener.stop()
+ listener.stop() # gh-114706 - ensure no crash if called again
self.assertTrue(handler.matches(levelno=logging.WARNING, message='1'))
self.assertTrue(handler.matches(levelno=logging.ERROR, message='2'))
self.assertTrue(handler.matches(levelno=logging.CRITICAL, message='3'))
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]