gh-132106: Allow logging.handlers.QueueListener to be used as a context manager (#132107)

This commit is contained in:
Charles Machalow 2025-04-12 05:00:04 -07:00 committed by GitHub
parent ad3bbe8fbc
commit 517e96b9ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 54 additions and 6 deletions

View file

@ -1532,6 +1532,19 @@ class QueueListener(object):
self._thread = None
self.respect_handler_level = respect_handler_level
def __enter__(self):
"""
For use as a context manager. Starts the listener.
"""
self.start()
return self
def __exit__(self, *args):
"""
For use as a context manager. Stops the listener.
"""
self.stop()
def dequeue(self, block):
"""
Dequeue a record and return it, optionally blocking.