Adding timeout to sys.stdin.read(1)
-
I am trying to read from the serial and telnet using sys.stdin.read(1). Since the function is blocking, I tried some suggested options with uselect:
import sys, uselect spoll=uselect.poll() spoll.register(sys.stdin, uselect.POLLIN) def read1(): return(sys.stdin.read(1) if spoll.poll(0) else None)However, I get the following error:
OSError: stream operation not supportedon the following line:spoll.register(sys.stdin, uselect.POLLIN)Any suggestion for non-blocking read of UART and Telnet using non-blocking calls?
Thank you in advance!
-
@jcaron unfortunately, there is any method with the
stdinand I haven't found any way to interact directly with the telnet server.My previous implementation used the UART, but then I realized that I was able to read from Telnet, but no way to type anything. Also, the telnet connection was quite slow and unreliable for some reason (time out when login/password). With
stdinit works much better, but not typing anything will block the application forever.
-
@berni have you tried setting it to non-blocking?
If using the UART directly there is an
anymethod which tells you if there’s data available, not sure if that is available via thestdininterface nor if that would work with telnet.