Skip to content

Commit e676457

Browse files
fix: use sys.__stdout__ to get real fd when PRINT_BUFFER replaces sys.stdout
Co-Authored-By: unknown <>
1 parent 0e32124 commit e676457

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

airbyte_cdk/entrypoint.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,21 @@ def _nonblocking_write_to_stdout(messages: Iterable[str]) -> None:
403403
resumes reading, ``select()`` returns, the write completes, the main
404404
thread resumes draining the queue, and workers unblock automatically.
405405
"""
406+
# Use the *real* stdout (sys.__stdout__) rather than sys.stdout,
407+
# because PRINT_BUFFER replaces sys.stdout with a StringIO wrapper
408+
# that has no fileno().
409+
real_stdout = sys.__stdout__
410+
if real_stdout is None or not hasattr(real_stdout, "fileno"):
411+
for message in messages:
412+
print(f"{message}\n", end="")
413+
return
414+
406415
try:
407-
stdout_fd = sys.stdout.fileno()
416+
stdout_fd = real_stdout.fileno()
408417
original_blocking = os.get_blocking(stdout_fd)
409418
os.set_blocking(stdout_fd, False)
410419
except OSError:
411-
# Fallback: if we cannot set non-blocking (e.g. pytest captures
412-
# stdout with a StringIO that has no fileno, or the fd does not
420+
# Fallback: if we cannot set non-blocking (e.g. the fd does not
413421
# support non-blocking mode), just write normally.
414422
for message in messages:
415423
print(f"{message}\n", end="")

0 commit comments

Comments
 (0)