Skip to content

Commit d6321c2

Browse files
committed
Don't run flask in threaded mode in webview test app
When flask is run in threaded mode, it creates a new thread to handle each response. In that case, Java classes found with jnius will use the system class loader instead of the app class loader since the new thread has no stack frame back to the app. Normally you'd resolve the classes first, but the test app is explicitly trying to delay loading the classes until needed. That won't work from new native threads.
1 parent 243e6b6 commit d6321c2

File tree

1 file changed

+9
-4
lines changed
  • testapps/on_device_unit_tests/test_app

1 file changed

+9
-4
lines changed

testapps/on_device_unit_tests/test_app/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@
8585
app_flask.TESTS_TO_PERFORM = tests_to_perform
8686

8787
print('Current directory is ', realpath(curdir))
88-
if realpath(curdir).startswith('/data'):
89-
app_flask.app.run(debug=False)
90-
else:
91-
app_flask.app.run(debug=True)
88+
flask_debug = not realpath(curdir).startswith('/data')
89+
90+
# Flask is run non-threaded since it tries to resolve app classes
91+
# through pyjnius from request handlers. That doesn't work since the
92+
# JNI ends up using the Java system class loader in new native
93+
# threads.
94+
#
95+
# https://github.com/kivy/python-for-android/issues/2533
96+
app_flask.app.run(threaded=False, debug=flask_debug)
9297
else:
9398
# we don't have kivy or flask in our
9499
# requirements, so we run unittests in terminal

0 commit comments

Comments
 (0)