You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: replace sys.stdout/stderr with non-blocking proxies to prevent deadlock
Previous fix only redirected logging handler streams to the non-blocking
buffer queue. This was insufficient because other code paths (print()
calls, direct sys.stdout.write()) still wrote to the real pipe and could
block when the platform paused reading.
This commit adds two additional layers of protection:
1. _StdoutProxy: A proxy object that intercepts write() and flush()
calls, routing them through the unbounded buffer queue. All other
attribute access (encoding, fileno, buffer, etc.) is delegated to
the original stream object.
2. sys.stdout and sys.stderr are replaced with _StdoutProxy instances
inside _buffered_write_to_stdout(). This ensures that ANY write
from ANY thread goes through the non-blocking buffer.
3. Diagnostic logging via os.write(2, ...) confirms the buffered writer
is active and reports how many handlers were redirected and the
original stdout/stderr types.
The three layers (handler redirection, stdout/stderr replacement, and
the writer thread) together ensure no thread ever blocks on the stdout
pipe except the dedicated writer thread.
Co-Authored-By: unknown <>
0 commit comments