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
esp8266: can't read from sys.stdin
I was trying to work around the fact that the ESP8266 port doesn't have UART support on the Python side yet, and simply read/write from and to the sys.stdin and sys.stdout.
While sys.stdout works as expected, trying to read even a single character from sys.stdin hangs the REPL. I compared with other ports, and that's not the case in them -- they wait until the specified number of characters is input and then properly return those characters.