Skip to content

Commit

Permalink
add a jnius.detach() method to detach a thread that used some jni.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tito committed Feb 7, 2015
1 parent 614e436 commit 857e4c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions jnius/jni.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,5 @@ cdef extern from "jni.h":

ctypedef struct JNIInvokeInterface:
jint (*AttachCurrentThread)(JavaVM *, JNIEnv **, void *)
jint (*DetachCurrentThread)(JavaVM *)

2 changes: 1 addition & 1 deletion jnius/jnius.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions jnius/jnius_env.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ cdef JNIEnv *get_jnienv() except NULL:
jvm[0].AttachCurrentThread(jvm, &env, NULL)
return env


def detach():
jvm[0].DetachCurrentThread(jvm)

0 comments on commit 857e4c7

Please sign in to comment.