mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-132106: Allow logging.handlers.QueueListener
to be used as a context manager (#132107)
This commit is contained in:
parent
ad3bbe8fbc
commit
517e96b9ed
6 changed files with 54 additions and 6 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue