add a jnius.detach() method to detach a thread that used some jni.

This cannot be automatic as jnius do not control the thread creation, so it cannot add a callabck to autocall this method.
It must be added by the user before the thread leave, if it used pyjnius inside.

Ref #107
Ref #97
This commit is contained in:
Mathieu Virbel 2015-02-07 19:33:19 +01:00
parent 614e43626a
commit 857e4c762a
3 changed files with 6 additions and 1 deletions

View File

@ -401,4 +401,5 @@ cdef extern from "jni.h":
ctypedef struct JNIInvokeInterface:
jint (*AttachCurrentThread)(JavaVM *, JNIEnv **, void *)
jint (*DetachCurrentThread)(JavaVM *)

View File

@ -87,7 +87,7 @@ Python::
__all__ = ('JavaObject', 'JavaClass', 'JavaMethod', 'JavaField',
'MetaJavaClass', 'JavaException', 'cast', 'find_javaclass',
'PythonJavaClass', 'java_method')
'PythonJavaClass', 'java_method', 'detach')
from libc.stdlib cimport malloc, free
from functools import partial

View File

@ -19,3 +19,7 @@ cdef JNIEnv *get_jnienv() except NULL:
jvm[0].AttachCurrentThread(jvm, &env, NULL)
return env
def detach():
jvm[0].DetachCurrentThread(jvm)