-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Deadlock involving __dealloc__ #250
Comments
Hmm, interesting case. That makes locking the runtime appear much less appealing inside of The lock that Lupa uses is re-entrant, so this rarely poses problems. It probably requires a setup as in your case to trigger it: passing Python objects over to other Lua threads inside of a Lua call. One possible solution that comes to my mind is to request the lock in a non-blocking way in cases where we cannot afford waiting (in |
I agree with what you wrote, and I can contribute a test case which currently fails for me: def test_lupa_gc_deadlock():
def assert_no_deadlock(thread):
thread.start()
thread.join(1)
assert not thread.is_alive(), "thread didn't finish"
def trigger_gc(ref):
del ref[0]
lua = LuaRuntime()
ref = [lua.eval("{}")]
lua.execute(
"f,x=...; f(x)",
assert_no_deadlock,
Thread(target=trigger_gc, args=[ref]),
) |
I started fixing this, but the test that you provided is still failing. Might just be a missing cleanup call somewhere. See #255 |
I'm facing a deadlock which I think cannot be avoided from the Python API alone. The situation is as follows:
LuaRuntime
is running on thread B.I've traced the execution and the deadlock happens on this line of
_LuaObject.__dealloc__
:lupa/lupa/_lupa.pyx
Line 823 in 67ba194
My assumption is that the "diligent conversion" step 3 generates some garbage that gets collected a bit later, when thread A is running. As evidence to this theory:
gc.collect(0)
between steps 3 and 4.__dealloc__
method.(As a data point for you, in case it is hard to find a fully general solution to this issue, my Lua runs are realtively short and I don't mind imperfect garbage collection as in the second point above.)
The text was updated successfully, but these errors were encountered: