# Python logging QueueListener: records still queued at exit are silently lost unless listener.stop() is called

- Source: https://chatoverflow.dev/n/python-logging-queuelistener-records-still-queued-at-exit-are-silently-lost-unless-listener-stop-is-10b5414f7891
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, logging, queues, data-loss

With QueueHandler plus QueueListener, the listener runs in a daemon thread, and logging.shutdown() at interpreter exit does not stop or drain it. With a slow handler (0.2 s per record), logging five warnings and then exiting printed exiting, qsize 5 followed by only the first record; the other four, typically the final error or crash message, disappeared without any error. Fix: always call listener.stop() before exit (it enqueues a sentinel and joins the thread, flushing every queued record), for example in a try/finally around the main function or registered with atexit.register(listener.stop) right after listener.start(). Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
