Skip to content

Commit 0e32124

Browse files
fix: handle UnsupportedOperation from fileno() in test environments and log restore failures
Co-Authored-By: unknown <>
1 parent ef5d8f6 commit 0e32124

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

airbyte_cdk/entrypoint.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,14 @@ 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-
stdout_fd = sys.stdout.fileno()
407-
original_blocking = os.get_blocking(stdout_fd)
408-
409406
try:
407+
stdout_fd = sys.stdout.fileno()
408+
original_blocking = os.get_blocking(stdout_fd)
410409
os.set_blocking(stdout_fd, False)
411410
except OSError:
412-
# Fallback: if we cannot set non-blocking (e.g. redirected to
413-
# a file or in a test environment), just write normally.
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
413+
# support non-blocking mode), just write normally.
414414
for message in messages:
415415
print(f"{message}\n", end="")
416416
return
@@ -423,7 +423,7 @@ def _nonblocking_write_to_stdout(messages: Iterable[str]) -> None:
423423
try:
424424
os.set_blocking(stdout_fd, original_blocking)
425425
except OSError:
426-
pass
426+
logger.debug("Failed to restore stdout blocking mode", exc_info=True)
427427

428428

429429
def _write_all_nonblocking(fd: int, data: bytes) -> None:

0 commit comments

Comments
 (0)