This starts up a background thread to monitor the queue for
LogRecords to process.
+ .. versionchanged:: next
+ Raises :exc:`RuntimeError` if called and the listener is already
+ running.
+
.. method:: stop()
Stops the listener.
manager protocol, allowing it to be used in a :keyword:`with` statement.
(Contributed by Charles Machalow in :gh:`132106`.)
+* :meth:`QueueListener.start <logging.handlers.QueueListener.start>` now
+ raises a :exc:`RuntimeError` if the listener is already started.
+ (Contributed by Charles Machalow in :gh:`132106`.)
+
mimetypes
---------
This starts up a background thread to monitor the queue for
LogRecords to process.
"""
+ if self._thread is not None:
+ raise RuntimeError("Listener already started")
+
self._thread = t = threading.Thread(target=self._monitor)
t.daemon = True
t.start()
listener.stop()
self.assertIsNone(listener._thread)
+ def test_queue_listener_multi_start(self):
+ handler = TestHandler(support.Matcher())
+ with logging.handlers.QueueListener(self.queue, handler) as listener:
+ self.assertRaises(RuntimeError, listener.start)
+
+ with listener:
+ self.assertRaises(RuntimeError, listener.start)
+
+ listener.start()
+ listener.stop()
+
def test_queue_listener_with_StreamHandler(self):
# Test that traceback and stack-info only appends once (bpo-34334, bpo-46755).
listener = logging.handlers.QueueListener(self.queue, self.root_hdlr)
--- /dev/null
+:meth:`QueueListener.start <logging.handlers.QueueListener.start>` now\r
+raises a :exc:`RuntimeError` if the listener is already started.\r