Skip to content

Commit eeea8a1

Browse files
authored
Merge pull request kivy#2597 from dbnicholson/webview-testapp-jnius
Fix webview testapp jnius usage
2 parents 4d45f99 + d6321c2 commit eeea8a1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

testapps/on_device_unit_tests/test_app/app_flask.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def loadUrl():
110110
print('asked to open url', args['url'])
111111
activity = get_android_python_activity()
112112
activity.loadUrl(args['url'])
113+
return ('', 204)
113114

114115

115116
@app.route('/vibrate')
@@ -122,7 +123,8 @@ def vibrate():
122123
if 'time' not in args:
123124
print('ERROR: asked to vibrate but without time argument')
124125
print('asked to vibrate', args['time'])
125-
return vibrate_with_pyjnius(int(float(args['time']) * 1000))
126+
vibrate_with_pyjnius(int(float(args['time']) * 1000))
127+
return ('', 204)
126128

127129

128130
@app.route('/orientation')
@@ -135,4 +137,5 @@ def orientation():
135137
print('ERROR: asked to orient but no dir specified')
136138
return 'No direction specified '
137139
direction = args['dir']
138-
return set_device_orientation(direction)
140+
set_device_orientation(direction)
141+
return ('', 204)

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)