-
Notifications
You must be signed in to change notification settings - Fork 186
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
Flask app can't debug within jpype #279
Comments
Best guess would be to enable a core dump and then load the core dump to get the backtrace. What is reported in the current log is in FindClass. So we can look at the possible sources there. jclass JPJavaEnv::FindClass(const char* a0)
{ jclass res;
JNIEnv* env = getJNIEnv();
void* _save = JPEnv::getHost()->gotoExternal();
res = env->functions->FindClass(env, a0);
JPEnv::getHost()->returnExternal(_save);
JAVA_CHECK("FindClass");
return res;
} Possible causes are I am not aware of the functions in that layer of the code. It appears to be dealing with threading. void* PythonHostEnvironment::gotoExternal()
{
PyThreadState *_save;
_save = PyEval_SaveThread();
return (void*)_save;
}
void PythonHostEnvironment::returnExternal(void* state)
{
PyThreadState *_save = (PyThreadState *)state;
PyEval_RestoreThread(_save);
} My best guess is that the JVM is being used from more than one thread in the app and that something has gone wrong in the bookkeeping in the jpype C++ module. I know that we have tests for threading safety, but this is not a feature that I have used. The only other way to debug this would be to compile with the jpype tracing feature on. It may give you a log of what jpype calls were. The if the calls before the crash look suspect then we could figure out which call corrupted the state. Looking a bit deeper it says pretty much what I though. Unless the jvm is null we can't hit that point. But it does show that jvm->functions cant be null itself as we would crash in this function. It jint JPJavaEnv::GetEnv(JNIEnv** env)
{
if (jvm == NULL)
{
*env = NULL;
return JNI_EDETACHED;
}
// This function must not be put in GOTO_EXTERNAL/RETURN_EXTERNAL because it is called from WITHIN such a block already
jint res;
res = jvm->functions->GetEnv(jvm, (void**)env, JNI_VERSION_1_2);
return res;
} @marscher I do see one bug in this path. JNIEnv* JPJavaEnv::getJNIEnv()
{
JNIEnv* env;
GetEnv(&env); <<< NOTHING IS LOOKING AT THE RETURN CODE
return env;
} This also looks like another case where we just have too many layers in the onion. The
|
we should definitely fix that getenv error code and raise something meaningful. Thanks for the catch! |
This should be correct in master. |
I have a flask app, start JVM and
attachThreadToJVM()
,when use
app.run(threaded=True, debug=True)
to debug the app, exception is as bellow.when use
app.run( debug=True)
to debug the app, exception is as bellow.:threaded
args meansshould the process handle each request in a separate thread?
so I think it is cased by JVM is not attached flask app threads.
The text was updated successfully, but these errors were encountered: