Detach only on android

This commit is contained in:
Akshay Arora 2016-10-26 20:42:55 +05:30 committed by GitHub
parent 9838660626
commit b5a1ecb7ec
1 changed files with 13 additions and 8 deletions

View File

@ -39,11 +39,16 @@ PythonJavaClass = PythonJavaClass_
# from https://gist.github.com/tito/09c42fb4767721dc323d
import threading
orig_thread_run = threading.Thread.run
def thread_check_run(*args, **kwargs):
if "ANDROID_ARGUMENT" in os.environ:
# on android, catch all exception to ensure about a jnius.detach
import threading
import jnius
orig_thread_run = threading.Thread.run
def jnius_thread_hook(*args, **kwargs):
try:
return orig_thread_run(*args, **kwargs)
finally:
jnius.detach()
threading.Thread.run = thread_check_run
threading.Thread.run = jnius_thread_hook