Skip to content

non-blocking reads of binary and text streams handle no-data differently #146394

@sh1boot

Description

@sh1boot

Bug report

Bug description:

proc = subprocess.Popen(
    ['bash', '-c', 'sleep 10; echo hello'],
    stdout=subprocess.PIPE,
    text=True
)
os.set_blocking(proc.stdout.fileno(), False)
print(repr(proc.stdout.read(8192)))

Refer to issue #57531 for discussion on what should happen in general, but I'm filing this to point out that when text=True the output is an empty string (indistinguishable from EOF, which is a problem), and when text=False the result is None (while an empty string is produced only on EOF).

They should probably behave consistently, and also EOF should be distinguishable from no-data-yet; making the binary behaviour preferable.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-subprocessSubprocess issues.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions