8000 unix/unix_mphal: Raise KeyboardInterrupt straight from signal handler. by pfalcon · Pull Request #1733 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

unix/unix_mphal: Raise KeyboardInterrupt straight from signal handler. #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

pfalcon
Copy link
Contributor
@pfalcon pfalcon commented Dec 19, 2015

POSIX doesn't guarantee something like that to work, but it works on any
system with careful signal implementation. Roughly, the requirement is
that signal handler is executed in the context of the process, its main
thread, etc. This is true for Linux.

POSIX doesn't guarantee something like that to work, but it works on any
system with careful signal implementation. Roughly, the requirement is
that signal handler is executed in the context of the process, its main
thread, etc. This is true for Linux.
@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 19, 2015

So, this is the most efficient solution for #1722, which is however not guaranteed to work on any OS. This needs to be tested on MacOSX and FreeDOS. As patch, there's going to be provision for old behavior anyway, suggestion for config var name are welcome. (Note that it will select either efficient async raising of KeyboardInterrupt, or caching it like before and them polling at various points of code, which is yet to be implemented).

pfalcon referenced this pull request Dec 19, 2015
Compiles with mingw32, tested to work erratically under Wine due to
not fully implemented emulation in it.
@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 20, 2015

@blmorris , @Anton-2, @pohmelie : Please help test this patch on your OSes.

@pohmelie
Copy link
Contributor

@pfalcon, what test should we do? Ctrl-c on repl? Or sys.stdin… from linked issue?

@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 20, 2015

@pohmelie : Yes, cases quickly described in 2195046#commitcomment-15080573 . Let me know if something is unclear there, I'll write up detailed test script.

@Anton-2
Copy link
Contributor
Anton-2 commented Dec 20, 2015

Rock solid on OS X (10.11.3 beta, clang-700.1.81). Tried 64 and 32 bit build, on repl and executing scripts, during syscall and busy loops.
Got a KeyboardInterrupt each time, even on repeated Ctrl-C.

@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 20, 2015

@Anton-2 : Great, thanks!

@pohmelie
Copy link
Contributor

@pfalcon
Almost all cases are ok. Except executing script with sys.stdin.read(1). There is no KeyboardInterrupt until I press enter. Also, if I try ctrl-c in repl it looks like it actually do enter, even on unix build.

$ ./micropython
MicroPython v1.4.5-654-g37f414f on 2015-12-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> 
>>> 
>>> fooTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'foo' is not defined
>>> 

@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 22, 2015

Also,

Worth a separate bugreport: #1742

@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 22, 2015

Except executing script with sys.stdin.read(1). There is no KeyboardInterrupt until I press enter.

Let's go step by step:

$ cat kbdintr1.py 
import sys
sys.stdin.read(1)
$ micropython kbdintr1.py 
^CTraceback (most recent call last):
  File "kbdintr1.py", line 2, in <module>
KeyboardInterrupt: 

I pressed just Ctrl+C above. Do you say that with djgpp build, pressing Ctrl+C doesn't have any effect, only when you make .read() to return (by finishing line input by pressing Enter), only then traceback with KeyboardInterrupt is printed? It's hard to explain such behavior, especially if it works as expected in REPL.

@dpgeorge
Copy link
Member

If this patch does actually work then I'd say go for it! It's nice and efficient.

@pfalcon
Copy link
Contributor Author
pfalcon commented Dec 22, 2015

Anyway, I'm merging this, as it's proven to work on MacOSX. I added config setting to enable this feature, it's off by default, by on for unix port. @pohmelie , if you think that freedos is better of without, please submit a patch to override it in mpconfigport_freedos.h

@pfalcon pfalcon closed this Dec 22, 2015
@pfalcon pfalcon deleted the async-kbdintr branch December 22, 2015 22:10
@pohmelie
Copy link
Contributor

@pfalcon
Yes, your "step by step" and result is right. I'm also don't know why this is possible. And I think it's ok to leave this as is right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0