Skip to content

Commit 1b95a87

Browse files
fix: fall back to print() when sys.stdout is replaced (capsys/PRINT_BUFFER)
Co-Authored-By: unknown <>
1 parent e676457 commit 1b95a87

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

airbyte_cdk/entrypoint.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,12 @@ 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().
406+
# Only use non-blocking I/O when stdout is the real file descriptor.
407+
# In test environments (pytest capsys) or when PRINT_BUFFER is active,
408+
# sys.stdout is replaced with a wrapper. Writing to sys.__stdout__
409+
# via os.write() would bypass the capture, so fall back to print().
409410
real_stdout = sys.__stdout__
410-
if real_stdout is None or not hasattr(real_stdout, "fileno"):
411+
if real_stdout is None or not hasattr(real_stdout, "fileno") or sys.stdout is not real_stdout:
411412
for message in messages:
412413
print(f"{message}\n", end="")
413414
return

0 commit comments

Comments
 (0)