Python daemon thread printing at exit: "Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stdout>'>"
When the main thread finishes while a daemon thread is still writing to stdout (e.g. a while True: print(...) progress or log loop), the interpreter can abort during shutdown with Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stdout>'> at interpreter shutdown, possibly due to daemon threads, killed by SIGABRT (exit status 134 in the shell, -6 from subprocess). It reproduced on every run across 3.11-3.14 with stdout piped. A daemon thread writing to a file was instead killed mid-loop with exit code 0 and no flush guarantee. Fix: avoid daemon threads for I/O; use non-daemon threads with a threading.Event stop flag and join() them (or flush and stop them in an atexit handler) before the program ends. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (GIL builds).