Comments (5)
The plot thickens:
In Windows, Ctrl-C actually creates a new thread for the handler
That means that even if we could interrupt the lua interpreter with the lua-error-throwing signal handler, we will still not be able to interrupt native code.
This problem also meets other languages
For example, try running this code in a python interpreter in windows:
import threading
threading.Event().wait()
Now try to ctrl-c: you can't.
EDIT:
actually, this is a better explaination of why windows ctrl c handling is wierd:
https://mail.python.org/pipermail/python-dev/2017-August/148800.html
from ilua.
This is extremely useful for bad interpreters:
$ ilua -i true
Jupyter console 6.1.0
ILua 0.2.1
In [1]: a2020-05-11T15:13:42+0200 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
Traceback (most recent call last):
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/usr/lib/python3.8/site-packages/ilua/kernelbase.py", line 196, in handle_message
content = yield self.do_is_complete(**msg['content'])
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1613, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks
_inlineCallbacks(None, g, status)
--- <exception caught here> ---
File "/usr/lib/python3.8/site-packages/ilua/kernelbase.py", line 196, in handle_message
content = yield self.do_is_complete(**msg['content'])
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/usr/lib/python3.8/site-packages/ilua/kernel.py", line 179, in do_is_complete
result = yield self.proto.sendRequest({"type": "is_complete",
builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto'
In [1]: a
/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py:656: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
warn('The kernel did not respond to an is_complete_request. '
2020-05-11T15:13:43+0200 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
Traceback (most recent call last):
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/usr/lib/python3.8/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1613, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks
_inlineCallbacks(None, g, status)
--- <exception caught here> ---
File "/usr/lib/python3.8/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/usr/lib64/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/usr/lib/python3.8/site-packages/ilua/kernel.py", line 126, in do_execute
result = yield self.proto.sendRequest({"type": "execute",
builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto'
^C2020-05-11T15:13:47+0200 [ilua.kernel.ILuaKernel#warn] ILua does not support keyboard interrupts
There seem to be no way out (except ^\
).
from ilua.
Hmm. I guess we could try to kill/respawn the interpreter on a second ctrl-c.
It's hardly a fix to the problem, but at least it's more user-friendly. I'll give it a thought.
from ilua.
Some kind of SIGINT-killing at least on Linux would be very much appreciated. Even if the interpreter dies afterwards, this is still better than not being able to interrupt at all.
from ilua.
I can just tweak the following in kernel.py:
def do_interrupt(self):
self.lua_process.signalProcess("INT")
return {'status': 'ok'}
It appears we need to return a status after reading https://jupyter-client.readthedocs.io/en/latest/messaging.html#msging-interrupt
Although it's apparently not critical.
This does work on Linux with interpreters respecting SIGINT. But it does leave the cell busy forever and the Lua error is never displayed. I can confirm that a Lua error is raised after the interruption and it still gets processed in ILuaKernel.do_execute()
. I suggest that the request_interrupt
message just gets in the way. Not sure how to send the reply_interrupt message only after the execution response.
So instead, I just set interrupt_mode to signal in kernel.json and ignore SIGINT via
signal.signal(signal.SIGINT, signal.SIG_IGN)
The signal still gets delivered to the child processes and thus to the Lua interpreter. This will allow loops to be interrupted properly, including displaying the Lua error. Cells will be idle after interruption. At least when running from the notebook (Web UI). Pressing CTRL+C in the Jupyter console apparently does not deliver the signal to the ILua kernel.
I am also not sure whether this change would be harmless on Windows.
from ilua.
Related Issues (20)
- What exactly is required from the custom lua interpreter? HOT 5
- Operation not permitted when piping in stdin HOT 2
- No such kernel named lua HOT 4
- RFE: A way to pass additional help_links from kernel.json HOT 3
- Install error on macOS HOT 4
- Installing to Jupyter's kernelspec? HOT 2
- Implement a backend running the kernel in the same process using lupa HOT 1
- Got error in jupyter lab HOT 19
- Exception 'coroutine' object is not subscriptable on typing anything HOT 11
- How to pip install ilua in specify lua version? HOT 4
- ilua in fedora 34 no docstrings, only ? HOT 1
- how to quit/close/exit ilua? HOT 2
- Exit cleanly when no Lua executable found HOT 1
- Tab-completion crashes HOT 7
- The included "inspect" module poorly respects __tostring metamethods
- builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto' HOT 10
- How to configure it? HOT 2
- Docstring crashing shell HOT 3
- printing HOT 7
- Passing ipython command line arguments HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ilua.