-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
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.
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). |
Compiles with mingw32, tested to work erratically under Wine due to not fully implemented emulation in it.
@pfalcon, what test should we do? Ctrl-c on repl? Or sys.stdin… from linked issue? |
@pohmelie : Yes, cases quickly described in 2195046#commitcomment-15080573 . Let me know if something is unclear there, I'll write up detailed test script. |
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. |
@Anton-2 : Great, thanks! |
@pfalcon $ ./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
>>> |
Worth a separate bugreport: #1742 |
Let's go step by step:
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. |
If this patch does actually work then I'd say go for it! It's nice and efficient. |
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 |
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.