You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
It also means our exception handling is poor as exceptions escaping the context are quietly swallowed. #221
I am bitten hardly by this now, as this type of error make the code hang, and no exception is printed.
It can be easily reproduced y running in embed a script which tried to load a "non existing python module".
If I run it in "embedded mode", the below exception is not visible, and the python+JVM hangs for ever.
I do see it, when running the same code in "non-embedded".
@behrica can you provide a little more context? "ModuleNotFoundError: No module named 'not existing' is a Python error, but 'not existing' is a very unusual module name. I feel like I would need more information to pinpoint why the error is not printing to the console, because I don't think I'd be able to reproduce this.
ARNING: Please consider reporting this to the maintainers of tech.v3.datatype.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f92b2d87d7a, pid=38488, tid=38488
#
# JRE version: OpenJDK Runtime Environment (11.0.16.1+1) (build 11.0.16.1+1)
# Java VM: OpenJDK 64-Bit Server VM (11.0.16.1+1, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C [libpython3.10.so.1.0+0x187d7a] PyImport_Import+0x3a
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/carsten/Dropbox/sources/libpython-clj/core.38488)
#
# An error report file with more information is saved as:
# /home/carsten/Dropbox/sources/libpython-clj/hs_err_pid38488.log
gives an Java exception (which I could probably catch):
ARNING: All illegal access operations will be denied in a future release
Exception in thread "Thread-0" Syntax error macroexpanding at (/home/carsten/Dropbox/sources/libpython-clj/crash2.clj:5:1).
at clojure.lang.Compiler.load(Compiler.java:7665)
at clojure.lang.Compiler.loadFile(Compiler.java:7591)
at clojure.lang.RT$3.invoke(RT.java:327)
at clojure.lang.Var.invoke(Var.java:384)
Caused by: java.lang.Exception: ModuleNotFoundError: No module named 'not existing'
at libpython_clj2.python.ffi$check_error_throw.invokeStatic(ffi.clj:708)
at libpython_clj2.python.ffi$check_error_throw.invoke(ffi.clj:706)
at libpython_clj2.python$import_module.invokeStatic(python.clj:165)
at libpython_clj2.python$import_module.invoke(python.clj:158)
at train$eval15837.invokeStatic(crash2.clj:6)
at train$eval15837.invoke(crash2.clj:5)
at clojure.lang.Compiler.eval(Compiler.java:7194)
at clojure.lang.Compiler.load(Compiler.java:7653)
... 3 more
Sep 30, 2022 10:30:39 AM clojure.tools.logging$eval3239$fn__3242 invoke
INFO: Reference thread starting
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/carsten/.local/lib/python3.10/site-packages/clojurebridge/cljbridge.py", line 187, in load_clojure_file
resolve_call_fn("clojure.core/load-file",
File "/home/carsten/.local/lib/python3.10/site-packages/clojurebridge/cljbridge.py", line 73, in resolve_call_fn
return resolve_fn(namespaced_fn_name)(*args)
File "/home/carsten/.local/lib/python3.10/site-packages/clojurebridge/cljbridge.py", line 50, in __call__
return invoker(*args)
File "/home/carsten/.local/lib/python3.10/site-packages/javabridge/jutil.py", line 961, in method
result = call(self.o, name, sig, *args)
File "/home/carsten/.local/lib/python3.10/site-packages/javabridge/jutil.py", line 892, in call
result = fn(*nice_args)
File "/home/carsten/.local/lib/python3.10/site-packages/javabridge/jutil.py", line 859, in fn
raise JavaException(x)
javabridge.jutil.JavaException: Syntax error macroexpanding at (/home/carsten/Dropbox/sources/libpython-clj/crash2.clj:5:1).
We can probably agree, that this is the expected behavior.
A JVM exception and neither "jvm crash" nor "jvm hanging".
Exception in thread "Thread-0" Syntax error macroexpanding at (/home/carsten/Dropbox/sources/libpython-clj/crash.clj:5:1).
at clojure.lang.Compiler.load(Compiler.java:7665)
at clojure.lang.Compiler.loadFile(Compiler.java:7591)
at clojure.lang.RT$3.invoke(RT.java:327)
at clojure.lang.Var.invoke(Var.java:384)
Caused by: java.lang.Exception: ModuleNotFoundError: No module named 'not existing'
You might ask, why do I play with "manul_gil" and GIL locking.
Because this makes python library simpletransformers work more reliable (proven by repeated executions and counting training sucecsses)
But by doing so, I experience now the issue we discuss. If I get an python exception in my code with "manuel GIL handling", it hangs.
As a "workaround" I now run it without manual GIL (to see if working on little data) and then switch to "with manual GIL" for train on full data, which is annoying to do.
Especially because the instability of simpletransformers might result in "hanging" as well (or JVM crash)
Well, I stand corrected :-). That definitely appears to be a bug in libpython-clj.
Perhaps the unlock-gil code needs check-error-throw. Hmm - that needs to happen nearly after every python call - it was handled by with-gil and it should still be happening.
Activity
behrica commentedon Sep 27, 2022
Just to not forget it.
I am bitten hardly by this now, as this type of error make the code hang, and no exception is printed.
It can be easily reproduced y running in embed a script which tried to load a "non existing python module".
If I run it in "embedded mode", the below exception is not visible, and the python+JVM hangs for ever.
I do see it, when running the same code in "non-embedded".
behrica commentedon Sep 27, 2022
I was not sure, if the fix would be here or in cljbridge,
so I opened this before:
behrica/clojurebridge#2
behrica commentedon Sep 27, 2022
behrica/clojurebridge#2 has some code snippets to reproduce it
behrica commentedon Sep 29, 2022
@cnuernber
Could you have a look at this ?
I am not able to dig myself, too much native and macro magic for me.
Each time my code hangs, I am always wondering if there was a python exception, which I just don't see.
jjtolton commentedon Sep 29, 2022
@behrica can you provide a little more context?
"ModuleNotFoundError: No module named 'not existing'is a Python error, but'not existing'is a very unusual module name. I feel like I would need more information to pinpoint why the error is not printing to the console, because I don't think I'd be able to reproduce this.behrica commentedon Sep 29, 2022
It happnes with "any exception" on python side, if using embedded mode and loading a script:
crash.clj;
Load the file in embedded:
behrica commentedon Sep 29, 2022
It "hangs" forever without printing any error
cnuernber commentedon Sep 29, 2022
This appears to me to be an issue with clojurebridge, not libpython-clj. Specifically javabridge's static call pathway must swallow exceptions.
Or I guess their make_method pathway.
behrica commentedon Sep 29, 2022
It does not happen with normal Clojure / JVM exceptions, that why I am wondering.
cnuernber commentedon Sep 29, 2022
Hmm. In that case something needs to check the python exception state and rethrow.
behrica commentedon Sep 30, 2022
Using
py/with-gilbehaves "better" (and different depending on "manual gil or not")....behrica commentedon Sep 30, 2022
So this code:
behrica commentedon Sep 30, 2022
called like this:
gives
behrica commentedon Sep 30, 2022
and called like this
gives an Java exception (which I could probably catch):
We can probably agree, that this is the expected behavior.
A JVM exception and neither "jvm crash" nor "jvm hanging".
behrica commentedon Sep 30, 2022
And we have the correct behaviour in the REPL, in "Non-embedded"
1 remaining item
behrica commentedon Sep 30, 2022
It is documented here:
https://clj-python.github.io/libpython-clj/embedded.html
chapter: Loading and running a Clojure file in embedded mode
behrica commentedon Sep 30, 2022
The new entry point is here:
https://github.com/behrica/clojurebridge/blob/2c3c6e6c6d3d74f61aa2d68d7bf1c770d76b09cc/src/clojurebridge/cljbridge.py#L173
I think I do the "same" as the other entry point:
https://github.com/behrica/clojurebridge/blob/2c3c6e6c6d3d74f61aa2d68d7bf1c770d76b09cc/src/clojurebridge/cljbridge.py#L142
behrica commentedon Sep 30, 2022
To make it more confusing, there is an other pathway I made as well, which loads a fixed "user.clj" file.
This prints as well teh exception.....
(I propose to later remove this
load_user_cljpathway, as it is superseded by theload_clojure_file)So lets ignore this for the moment,
I created: behrica/clojurebridge#5
behrica commentedon Sep 30, 2022
Let's concentrated on the "hanging" one, which is worst from a user experience point of view:
crash.clj
run as
results in
hanging for ever
expected behaviour
A nice JVM exception:
behrica commentedon Sep 30, 2022
(same hanning happens without calling "lock/gil")
and independent of the "manual_gil") setting, so we get an even easier hanging szenario:
behrica commentedon Sep 30, 2022
You might ask, why do I play with "manul_gil" and GIL locking.
Because this makes python library
simpletransformerswork more reliable (proven by repeated executions and counting training sucecsses)But by doing so, I experience now the issue we discuss. If I get an python exception in my code with "manuel GIL handling", it hangs.
As a "workaround" I now run it without manual GIL (to see if working on little data) and then switch to "with manual GIL" for train on full data, which is annoying to do.
Especially because the instability of
simpletransformersmight result in "hanging" as well (or JVM crash)behrica commentedon Sep 30, 2022
Even simpler code t reproduce:
Any exception thronw by pythonresult in "hanging"
clled like this:
cnuernber commentedon Sep 30, 2022
Well, I stand corrected :-). That definitely appears to be a bug in libpython-clj.
Perhaps the unlock-gil code needs check-error-throw. Hmm - that needs to happen nearly after every python call - it was handled by with-gil and it should still be happening.
behrica commentedon Sep 30, 2022
I found a way to at least print the error, but it still hang
behrica commentedon Sep 30, 2022
It gets as well solved by unlocking the gil in a
finallyI noticed already before, that in embedded mode and loading a clj file,
the JVM does not terminate without the
unlockSo the "hanging" we see is maybe the following:
The exception:
5, JVM hangs
behrica commentedon Sep 30, 2022
so maybe it is simpler to find out and fix that in the following the VM does not terminate:
behrica commentedon Sep 30, 2022
I saw that in the hanging state some thread seems to wait forever:
not sure, if relevant
cnuernber commentedon Sep 30, 2022
The java api has a try-with-resources pattern -
That will automatically do the try-finally. Anything auto-closeable will be closed in a with-open macro.
cnuernber commentedon Oct 2, 2022
There is a new API in latest (2.020) - with-manual-gil that will automatically lock/unlock the gil.
Outputs: