← index #3356Issue #16550
Related · medium · value 1.862
QUERY · ISSUE

[baremetal] sys.stdin does not handle ctrl-D EOF markers

openby dhalbertopened 2017-10-07updated 2017-10-21

sys.stdin.read(), sys.stdin.readlines(), etc. do not handle ctrl-D at the beginning of a line as EOF (except on ports like unix). So for instance, there's no way to terminate input when doing sys.stdin.readlines().

Is this something that should mimic CPython on an OS-less port? Some lower-level stream read routine could check if the stream was sys.stdin and handle ctrl-D specially.

(tested on esp8266 port)

CANDIDATE · ISSUE

select.poll not working properly with sys.stdin

openby cxxcoderopened 2025-01-08updated 2025-07-31
bug

Port, board and/or hardware

MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico with RP2040

MicroPython version

When using sys.stdin with select.poll and calling poll() or ipoll() to wait for available data, only sys.stdin.read(1) returns while sys.stdin.read() blocks.
However, reading only character by character is probably very inefficient and blows up code additionally.

Reproduction

import sys, select

import sys, select

p = select.poll()
p.register(sys.stdin, select.POLLIN)
while True:
    for o, _ in p.ipoll():
        if o is sys.stdin:
            read = sys.stdin.read()
            print('read', read)

Expected behaviour

sys.stdin.read() should immediately return when sending data to the serial interface on the PC the Pico is connected to.

Observed behaviour

sys.stdin.read() still blocks.
The same behavior when using sys.stdin.buffer instead of sys.stdin.
The code works when using sys.stdin.read(1) instead of sys.stdin.read()

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied