Skip to content

Commit 117b1be

Browse files
committed
fix for the problem with decorator run_on_ui_thread and the local reference table overflow
1 parent 1223337 commit 117b1be

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • pythonforandroid/recipes/android/src/android

pythonforandroid/recipes/android/src/android/runnable.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# reference to the activity
1111
_PythonActivity = autoclass(JAVA_NAMESPACE + '.PythonActivity')
1212

13+
#cache of functions table
14+
__functionstable__ = {}
1315

1416
class Runnable(PythonJavaClass):
1517
'''Wrapper around Java Runnable class. This class can be used to schedule a
@@ -27,6 +29,7 @@ def __call__(self, *args, **kwargs):
2729
self.args = args
2830
self.kwargs = kwargs
2931
Runnable.__runnables__.append(self)
32+
3033
_PythonActivity.mActivity.runOnUiThread(self)
3134

3235
@java_method('()V')
@@ -38,12 +41,24 @@ def run(self):
3841
traceback.print_exc()
3942

4043
Runnable.__runnables__.remove(self)
44+
45+
4146

4247

4348
def run_on_ui_thread(f):
4449
'''Decorator to create automatically a :class:`Runnable` object with the
4550
function. The function will be delayed and call into the Activity thread.
4651
'''
52+
53+
if f not in __functionstable__:
54+
55+
rfunction = Runnable(f) #store the runnable function
56+
57+
__functionstable__[f] = {"rfunction":rfunction}
58+
59+
rfunction = __functionstable__[f]["rfunction"]
60+
4761
def f2(*args, **kwargs):
48-
Runnable(f)(*args, **kwargs)
62+
rfunction(*args, **kwargs)
63+
4964
return f2

0 commit comments

Comments
 (0)