Skip to content
New issue

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

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

Already on GitHub? # to your account

builtins.AttributeError: 'ILuaKernel' object has no attribute 'proto' #30

Open
hs3434 opened this issue Dec 11, 2023 · 10 comments
Open

Comments

@hs3434
Copy link

hs3434 commented Dec 11, 2023

`In [1]: print'sasd'
2023-12-11T16:11:05+0800 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
Traceback (most recent call last):
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
result = context.run(gen.send, result)
File "/home/husheng/local/lib/python3.11/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2256, in unwindGenerator
return _cancellableInlineCallbacks(gen)
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2168, in _cancellableInlineCallbacks
_inlineCallbacks(None, gen, status, _copy_context())
--- ---
File "/home/husheng/local/lib/python3.11/site-packages/ilua/kernelbase.py", line 193, in handle_message
content = yield self.do_execute(**msg['content'])
File "/home/husheng/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
result = context.run(gen.send, result)
File "/home/husheng/local/lib/python3.11/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'

^Z
[4]+ 已停止 ilua`

`(base) [husheng@node26 convert]$ pip show ilua

Name: ilua
Version: 0.2.1
Summary: Portable Lua kernel for Jupyter
Home-page: https://github.com/guysv/ilua
Author: Guy Sviry
Author-email: sviryguy@gmail.com
License: GPLv2
Location: /home/husheng/local/lib/python3.11/site-packages
Requires: jupyter-console, jupyter-core, pygments, termcolor, twisted, txzmq
Required-by: `
I use Python 3.11.6 in a linux platform, This error will show up no matter what command I type.

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

I'm getting the same problem on Python 3.12.1. I updated to Fedora 39 and suddenly ilua does not work.

$ ilua
Jupyter console 6.6.3

ILua 0.2.1
In [1]: 2023-12-13T14:39:40+0100 [ilua.kernel.ILuaKernel#critical] Uncought exception in message handler
	Traceback (most recent call last):
	  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
	    result = context.run(gen.send, result)
	  File "/usr/lib/python3.12/site-packages/ilua/kernelbase.py", line 196, in handle_message
	    content = yield self.do_is_complete(**msg['content'])
	  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 2256, in unwindGenerator
	    return _cancellableInlineCallbacks(gen)
	  File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 2168, in _cancellableInlineCallbacks
	    _inlineCallbacks(None, gen, status, _copy_context())
	--- <exception caught here> ---
	  File "/usr/lib/python3.12/site-packages/ilua/kernelbase.py", line 196, in handle_message
	    content = yield self.do_is_complete(**msg['content'])
          File "/usr/lib/python3.12/site-packages/twisted/internet/defer.py", line 2000, in _inlineCallbacks
	    result = context.run(gen.send, result)
	  File "/usr/lib/python3.12/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'
	
/usr/lib/python3.12/site-packages/jupyter_console/ptshell.py:787: 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. '
In [1]: 

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

downgrading twisted to 22.10 makes it work

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

FWIW it seems that this is called:

ilua/ilua/kernel.py

Lines 104 to 105 in 05eb181

self.proto = yield self.pipes.connect(
protocol.Factory.forProtocol(InterpreterProtocol))

And before the self.proto attribute is set, other methods (such as do_is_complete) proceed and fail.

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

I've tried bisecting this and I belive the problem started with twisted/twisted#1675

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

Adding usePTY=1 to this call forces fork-based process and makes it work.

I don't know yet why it does not work with posix_spawn or whether there is a nicer way to force fork.

ilua/ilua/kernel.py

Lines 96 to 100 in 05eb181

self.lua_process = self.reactor.spawnProcess(proto,
self.lua_interpreter,
[self.lua_interpreter,
INTERPRETER_SCRIPT],
None)

@hroncok
Copy link
Contributor

hroncok commented Dec 13, 2023

Setting self.reactor._neverUseSpawn = True (which is obviously a hack) also works.

EDIT: That's what I did for now in the Fedora package.

@guysv
Copy link
Owner

guysv commented Dec 14, 2023

man you fucking rock. im gonna go over this and see what's up. I'm aware something broke in twisted but I stalled the downgrade because 22.10 doesn't seem stable on my machine. I needed that nudge to dig deeper 🙏

@guysv
Copy link
Owner

guysv commented Dec 21, 2023

hi guys can you try this snapshot:
https://github.com/guysv/ilua/releases/tag/0.2.1%2Bpass.env.explicit.1

after failing with 22.10, i noticed there's some failed assertion for env-var read (interp.lua:8)
tried to do e68fadb. works for me. give it a try and report back?

this works even with latest twisted

@JIghtuse
Copy link

JIghtuse commented Jan 7, 2024

@guysv, e68fadb works for me. I've seen reproduction of exception above, and with manually patched kernel.py the exception gone.

@guysv
Copy link
Owner

guysv commented Jan 7, 2024

nice. looks like some time during twisted's transition to spawn-by-default subprocessing, their wrapper stopped implicitly passing current process environment to the child, which looks like I assumed. copying the dict seems like a reasonable workaround. Mac seems to be not stable at all still. need to dig into that before a release i guess.

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

No branches or pull requests

4 participants