← index #16550Issue #11253
Related · high · value 1.430
QUERY · 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

CANDIDATE · ISSUE

On RP2 sys.stdin.read(64) and sys.stdin.readline() do not work if we have multiple of 64 bytes in buffer

closedby pchalaopened 2023-04-13updated 2023-04-25
port-rp2

MicroPython v1.19.1-994-ga4672149b on 2023-03-29; Raspberry Pi Pico with RP2040

Pico code:

import sys

while True:
    line = sys.stdin.read(64)
    print(len(line))

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