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...Being able to interrupt the main thread is something I have on my todo list
Telling if char is pending in input
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Telling if char is pending in input
@dhlands
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Telling if char is pending in input
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
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
Re: Telling if char is pending in input
Interestingly, MicroPython v1.5-297-gf2ed736 on linux, does this:Roberthh wrote:pressed Ctrl-C and got: a segmentation fault!
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: 4
Re: Telling if char is pending in input
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.