File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 = "" )
You can’t perform that action at this time.
0 commit comments