[issue39589] Logging QueueListener should support context manager

Simon report at bugs.python.org
Wed Feb 19 11:08:37 EST 2020


Simon <sfbbrugman at gmail.com> added the comment:

The QueueListener in the logging library starts a background thread to monitor the log event queue. The context manager support is ideal in this case, making the code simpler, more consistent with other classes (e.g. multiprocessing.Pool) and prompts stopping the thread.

Without support for the context manager we need the following code:

```
queue_listener = QueueListener(queue, handler)
queue_listener.start()
# queue messages
queue_listener.stop()
```

adding context manager support would result in the following equivalent code:

```
with QueueListener(queue, handler) as queue_listener:
    # queue messages
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39589>
_______________________________________


More information about the Python-bugs-list mailing list