]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-114706: Allow QueueListener.stop() to be called more than once. (GH-114748)
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 30 Jan 2024 12:34:18 +0000 (12:34 +0000)
committerGitHub <noreply@github.com>
Tue, 30 Jan 2024 12:34:18 +0000 (12:34 +0000)
Lib/logging/handlers.py
Lib/test/test_logging.py

index 9840b7b0aeba8840d8805198ff99469f6741316a..e7f1322e4ba3d9d048a59cf791606bc127071e55 100644 (file)
@@ -1586,6 +1586,7 @@ class QueueListener(object):
         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
index 908e242b85f5e7ac832525f4298e8a480267e4c3..888523227c2ac43026908f9f312c4dbe86fc5865 100644 (file)
@@ -4089,6 +4089,7 @@ class QueueHandlerTest(BaseTest):
             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'))