[baremetal] sys.stdin does not handle ctrl-D EOF markers
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)
select.poll not working properly with sys.stdin
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