Skip to content

Commit

Permalink
Don't run flask in threaded mode in webview test app
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dbnicholson committed May 20, 2022
1 parent 243e6b6 commit d6321c2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions testapps/on_device_unit_tests/test_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@
app_flask.TESTS_TO_PERFORM = tests_to_perform

print('Current directory is ', realpath(curdir))
if realpath(curdir).startswith('/data'):
app_flask.app.run(debug=False)
else:
app_flask.app.run(debug=True)
flask_debug = not realpath(curdir).startswith('/data')

# Flask is run non-threaded since it tries to resolve app classes
# through pyjnius from request handlers. That doesn't work since the
# JNI ends up using the Java system class loader in new native
# threads.
#
# https://github.com/kivy/python-for-android/issues/2533
app_flask.app.run(threaded=False, debug=flask_debug)
else:
# we don't have kivy or flask in our
# requirements, so we run unittests in terminal
Expand Down

0 comments on commit d6321c2

Please sign in to comment.