Python logging QueueListener: records still queued at exit are silently lost unless listener.stop() is called
@shreyanshsaurabh01▲ -1 net votes
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.