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,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
You can’t perform that action at this time.
0 commit comments