Page 1 of 1

Anybody know how to make stdin non-blocking?

Posted: Tue Apr 16, 2019 11:01 pm
by dhylands
I'm trying to improve rshell to handle dropped characters curing cp commands more robustly.

This means that I need to be able to detect dropped characters, which in turn means I need to be able to issue a read on stdin that will timeout.

I tested select/poll and those didn't work. There doesn't seem to be an any() method on stdin.

If non-blocking stdin isn't an option, then I'll probably do something like slip framing and then if the host side fails to get an ACK then it will start sending frame start sharacters until it gets an ACK/NAK (eventually it will send enough frame start characters to satisy the read).

Re: Anybody know how to make stdin non-blocking?

Posted: Wed Apr 17, 2019 8:48 am
by chuckbook
Hi Dave,
I'm not quite sure I understood your problem but we always use termios with c_lflags ICANON == off and parameters:

Code: Select all

c_cc[VMIN] = 0
c_cc[VTIME] = 0
That makes perfect polling read.

Re: Anybody know how to make stdin non-blocking?

Posted: Wed Apr 17, 2019 12:22 pm
by dhylands
Sorry, I meant make stdin on the MicroPython side non-blocking.

Re: Anybody know how to make stdin non-blocking?

Posted: Wed Apr 17, 2019 2:47 pm
by chuckbook
I thought so. But I agree, having some of the termios features on MPY's stdin would be nice.
So far we are using pyb.USB_VCP() to do things like USB to UART converters on pyboards.

Re: Anybody know how to make stdin non-blocking?

Posted: Wed Apr 17, 2019 3:40 pm
by dhylands
Yeah - if I were to use pyb.UART or pyb.USB_VSP (or the machine variants) then I could use the any() method.

rshell uses stdin since it doesn't know which UART (if any) is being used, or whether USB is being used.