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
On RP2 sys.stdin.read(64) and sys.stdin.readline() do not work if we have multiple of 64 bytes in buffer
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))