This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: QueueHandler logs stack_info twice
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: emontnemery, erik.montnemery, vinay.sajip
Priority: normal Keywords: patch

Created on 2022-02-15 08:36 by erik.montnemery, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31355 open emontnemery, 2022-02-15 10:20
Messages (1)
msg413278 - (view) Author: Erik Montnemery (erik.montnemery) * Date: 2022-02-15 08:36
logging.handlers.QueueHandler logs stack twice when stack_info=True:

>>> import logging
>>> from logging.handlers import QueueHandler, QueueListener
>>> from queue import Queue
>>> q = Queue()
>>> logging.getLogger().addHandler(QueueHandler(q))
>>> listener = QueueListener(q, logging.StreamHandler())
>>> listener.start()
>>> _LOGGER.error("Hello", stack_info=True)
Stack (most recent call last):
  File "<stdin>", line 1, in <module>
Stack (most recent call last):
  File "<stdin>", line 1, in <module>

Reproduced on CPython 3.9.9, but the code is unchanged in 3.10 and 3.11, so the issue should exist there too.

Patching QueueHandler.prepare() to set stack_info to None seems to fix this:

diff --git a/Lib/logging/ b/Lib/logging/
index d42c48de5f..7cd5646d85 100644
--- a/Lib/logging/
+++ b/Lib/logging/
@@ -1452,6 +1452,7 @@ def prepare(self, record):
         record.args = None
         record.exc_info = None
         record.exc_text = None
+        record.stack_info = None
         return record

     def emit(self, record):

Related issue: Issue34334, with patch
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90911
2022-02-17 00:10:50ned.deilysetnosy: + vinay.sajip
2022-02-15 10:20:46emontnemerysetkeywords: + patch
nosy: + emontnemery

pull_requests: + pull_request29504
stage: patch review
2022-02-15 08:36:55erik.montnemerycreate