-
Notifications
You must be signed in to change notification settings - Fork 144
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
Help. Process finished with exit code 132 #241
Comments
I suspect something in your environment is not correct tor the pmdarima is not working in an embedded python. Can you try altering your function to do something that does not use pmdarima to verify that your environment is working. If that works then try to identify which specific line of your function is causing the crash and it may help narrow down what is wrong. |
I changed the python code, which is closer to what I need, I marked the place where I found the error; it is strange that it appears in the place where the model was advertised |
Hi, |
Hello, This on python runs without problems:
But this equivalent code running on Java through Jep fails with the same message (
Note that I running this method as a test in my project. The workaround that @plapa mentioned works for this example (i.e. change the line with Environment: OS Platform, Distribution, and Version: macOS Catalina, Version: 10.15.7 |
I think I was able to narrow down the issue to a couple of functions in I experimented using examples for both packages ( I was able to replicate the issue using a file
I created the
EDIT: I forgot to say that the error is produced after importing the module |
|
Thank you for the reply @bsteffensmeier ! Yes, we have been using I found about I created a small example executing these python commands through the python c-api and jep in the folder linked below. Yet again, the issue only occurs while running it through jep. I also don't see how jep and standalone python could use different versions of dependencies since they essentially use the same executable (at least the script through the C-API does). My only idea now is digging in scipy to see the exact point where it fails and then probably it will direct to lapack or blas implementations, but that seems a bit tedious. I was using Thank you! :) |
With signals the problem we have is that the some libraries attempt to install signal handlers from python and python will not install the signal handlers since it detects it is not on the main thread. The only way I can see that causing your problem is if something in python/scipy is supposed to catch that SIGILL but Java is getting it instead and crashing. Again, not sure if that is really plausible, I'm just trying to brainstorm and compare against problems we have seen before. Thank you for putting together your small example. I was able to run it on my ubuntu system. I do segfault when executing run.py from jep. It does not segfault from python or from c_meh, so it sounds like the same problem even though I don't see SIGILL. I was able to make the segfault dissappear by building scipy from source( Another difference between c_meh and jep(besides the entire JVM running) is the threading. You could try adding threading to c_meh and see if that is able to repeat the problem. I recently put together an isolated example of the python related threading in jep here. So if you modify that code to call py_meh you should be able to determine if it is threading related. Along the lines of threading, one of the problems we have come across in the past is that python offers some C-API calls that are incompatible with multiple interpreters. This is why Jep has come up with the restriction that only one interpreter can be used on a thread and this has solved all known issues related to this API, but it is possible you have discovered some new caveat that we need to work around. |
I built scipy from source and had some success with it! However, I still see the error occurring in other situations. I'll share when I have updates. :) |
Hi @bsteffensmeier ! This is just a short update. I updated the example in Yet again, the C code runs normally I integrated your example with threading and the code still works. Please check if that's what you meant. I don't fully understand your example because it seems to always be using a single thread and when I uncomment any of the commented lines, it immediately breaks. Thank you! EDIT: the updated example does not replicate the issue when I build scipy from source. |
In the multithreaded c example the commented out portion shows things that used to work in previous versions but do not work in the latest python. The code you have now which runs on_thread_3 is simulating what we do in jep 3.9.1 and should create one extra thread which is a good simplification of how SubInterpreter runs. The only change you need to make is to run your py_meh code in on_thread_3 instead of in main. In Jep the "main" python thread doesn't actually run anything. My theory with the recompile is that SIGILL indicates an illegal instruction and the most straightforward explanation for that is that the code was compiled on another machine with extra instructions that our CPUs don't support. Compiling locally should ensure the compiler only uses instructions which we actually have. But this doesn't really fit well with what you see where it fails in jep and not python. I am not aware of anything in jep or the JVM which could alter which instructions are used. My best recommendation would be to start digging into the scipy code to try to narrow down where it is crashing. |
It seems that running code in a subthread explains these failures! I updated the code example in the fork using your suggestions and the results of C and Jep are more consistent (though not completely...). Looking into the results of scipy tests ( I also had a couple of questions related to this. Excuse me if they are answered in the docs. Since the C code was working fine when it was executed in the main thread, is there an alternative to Thanks! |
There is currently no simple way for developers to access the main thread in Jep. Right now the only thing the main thread is doing after initialization is handling shared module imports. You could try to use that mechanism to run your code on the main thread. If you create a SubInterpreter with "run" as a shared module then "import run" in the SubInterpreter then the actual import logic will be executed in the main interpreter. I don't think that would be a useful solution but if you want to try it out and make sure it is stable on the main thread that is one way to try it. Another option would be to just import run from the jep c code. You could import run in pyembed_startup at the end before we release the thread.
I have never noticed this before but according to the threading documentation any threads that are not created by python use a dummy thread. Since Jep threads are created by java this seems like the correct behaviour to me. I'm surprised the subthread in c would not be a dummy thread, that may be a difference between sub-interpreter and shared-interpreter. The current code you have will create a SubInterpreter. Do you know if a SubInterpreter thread from Jep will be a Dummy or Main? If you want to try to test something closer to a shared interpreter from C then the code below could be used instead of on_thread_3. I have not tested it yet but it is simply the necessary parts from the jep source. I would expect that to be a dummy thread.
|
@bsteffensmeier I updated the examples in my fork By the way, just to be clear below, when I say "thread" or "main thread", I mean the outputs of the functions
The output of
After changing
and hadn't had success.
I used your snippet for
The thread of the Finally, there is a possible workaround for the issue pointed in this page by wrapping the python functions in a
It works with all the examples I gathered, but it gives little insight into why they break in threads created in C or Java. The best explanation is that C or Java may be catching some signal generated by python code that is usually ignored as you mentioned. |
I think this is really interesting. The C code in Jep, and in Another approach to looking at this might be to compare the |
This procedure shows that the code is executed in the same thread as The hint about tracking the matching C code looks promising. I wonder if the imports and/or "shared states"(?) will work well though. We'll see. In the meantime, I found the first line in https://github.com/python/cpython/blob/master/Lib/threading.py neat EDIT: the following link seems to describe the thread module in a more accessible way |
Success 🎉! The tldr of the fix I found was to increase the stack size of the threads or programs. In the meantime, I did not figure out what is the default stack size when I hope that this actually sorts out the issue and does not simply hide it because there was a lot of trial and error and I kind of found this simple fix by chance. I wonder what actions could follow up: a heads up in the documentation could be added (in the numpy, scipy section) or, if possible, a warning could be issued before the call stack increases beyond its limit. The longer story for how I found this is that I spent a lot of time checking if the computations could be affected by running
I also spent some time looking into the CPython source code, in particular the Finally, I increased the stack size of the Java program using Jep to 4 MB and the examples also worked well. |
It is awesome that you were able to track that all the way down, Thank you so much for reporting back what you found. I am not sure how to identify who would need to adjust the stack size but it is something simple we can recommend other people try when they run into problems. To sum up the simplest solution for anyone running across this thread in the future, You are just adding |
Thank you very much for always replying promptly, @bsteffensmeier :) |
I get an error when trying to run a function from java. What have I done wrong?
forecast.py:
Environment:
The text was updated successfully, but these errors were encountered: