Telling if char is pending in input

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Telling if char is pending in input

Post by pythoncoder » Tue Dec 15, 2015 7:53 am

@dhlands
Being able to interrupt the main thread is something I have on my todo list
In this instance @Roberthh is trying to convert a blocking read (sys.stdin.read(1)) into a nonblocking one. Would this be feasible under your proposed software interrupt scheme? The software interrupt occurs in the middle of the blocking read, and does its stuff. I get that. But somehow it needs to force the blocking read to terminate and normal program flow to resume. That sounds ambitious...
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Telling if char is pending in input

Post by Roberthh » Tue Dec 15, 2015 9:49 am

Hi all,
the code example above was just a trial to see, if stdin.read() could be interrupted by a timer event. That did not work, which is ok. Just a try. But more interesting is, that even the intended interrupt event Ctrl-C does not interrupt stdin.read(). While I'm writing this, I was just noisy in what Linux micropython would so. So at the REPL prompt I entered:

import sys
sys.stdin.read(1)

pressed Ctrl-C and got: a segmentation fault! Starting it with gdb, Ctrl-C falls back into the gdb prompt with the message:

Program received signal SIGINT, Interrupt.
0xb7fdbd22 in __kernel_vsyscall ()

B.t.w.: Windows Micropython just terminates, Phyton3 on both Linux and Windows deliver the expected keyboard interrupt message.
Regards

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Telling if char is pending in input

Post by platforma » Tue Dec 15, 2015 10:17 am

Roberthh wrote:pressed Ctrl-C and got: a segmentation fault!
Interestingly, MicroPython v1.5-297-gf2ed736 on linux, does this:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 4
And returns back to REPL. If I repeat the sys.stdin.read(1) and ctrl-c, it exists with no messages at all.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Telling if char is pending in input

Post by dhylands » Tue Dec 15, 2015 4:44 pm

I created an issue over here: https://github.com/micropython/micropython/issues/1722 and a potential solution for sys.stdin.read(1), but I think that this is a more systemic issue that needs to be addressed for every system call made.

Post Reply