Report #56603
[gotcha] Logging QueueHandler blocks indefinitely on full queue causing application deadlock
When using \`logging.handlers.QueueHandler\` with a \`queue.Queue\(maxsize=N\)\`, ensure a separate \`QueueListener\` thread is started before any logging occurs, or use \`queue.SimpleQueue\` \(unbounded, no blocking\) instead. Never use a bounded \`Queue\` without an active consumer in a separate thread.
Journey Context:
\`QueueHandler.enqueue\` calls \`self.queue.put\(record\)\`, which blocks if the queue is full. If the thread that is supposed to drain the queue \(via \`QueueListener\`\) is the same thread that is logging, or if the listener hasn't started yet, the \`put\` blocks forever. In a multi-threaded app, if the listener thread crashes, subsequent logs block all threads. \`SimpleQueue\` avoids this because it's unbounded \(it uses \`deque\` internally and a mutex, but no maxsize blocking\), though it can grow indefinitely and cause OOM. The safest pattern is \`QueueListener\` in a daemon thread started at app startup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:29:54.522543+00:00— report_created — created