Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1245f14

Browse files
activity.py: throttle async_call() to fix overflow
1 parentce57c1e commit1245f14

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

‎internal_filesystem/lib/mpos/app/activity.py‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
classActivity:
66

7+
throttle_async_call_counter=0
8+
79
def__init__(self):
810
self.intent=None# Store the intent that launched this activity
911
self.result=None
@@ -14,12 +16,14 @@ def onCreate(self):
1416
pass
1517
defonStart(self,screen):
1618
pass
17-
defonResume(self,screen):# app gets foreground
19+
20+
defonResume(self,screen):# app goes to foreground
1821
self._has_foreground=True
19-
mpos.ui.th.add_event_cb(self.thc,2)
22+
mpos.ui.th.add_event_cb(self.task_handler_callback,1)
2023

2124
defonPause(self,screen):# app goes to background
2225
self._has_foreground=False
26+
2327
defonStop(self,screen):
2428
pass
2529
defonDestroy(self,screen):
@@ -65,9 +69,8 @@ def finish(self):
6569
defhas_foreground(self):
6670
returnself._has_foreground
6771

68-
defthc(self,a,b):
69-
#print("thc called")
70-
self.counter=0
72+
deftask_handler_callback(self,a,b):
73+
self.throttle_async_call_counter=0
7174

7275
# Execute a function if the Activity is in the foreground
7376
defif_foreground(self,func,*args,**kwargs):
@@ -79,13 +82,13 @@ def if_foreground(self, func, *args, **kwargs):
7982
#print(f"[if_foreground] Skipped {func} because _has_foreground=False")
8083
returnNone
8184

82-
counter=0
8385
# Update the UI in a threadsafe way if the Activity is in the foreground
86+
# The call may get throttled, unless important=True is added to it.
8487
defupdate_ui_threadsafe_if_foreground(self,func,*args,important=False,**kwargs):
85-
self.counter+=1
86-
ifnotimportantandself.counter>250:
87-
#print(f"skipping because self.counter is {self.counter} and not important")
88-
return
88+
self.throttle_async_call_counter+=1
89+
ifnotimportantandself.throttle_async_call_counter>100:# 250 seems to be okay, so 100 is on the safe side
90+
print(f"update_ui_threadsafe_if_foreground called more than 100 times for one UI frame, which can overflow - throttling!")
91+
returnNone
8992
# lv.async_call() is needed to update the UI from another thread than the main one (as LVGL is not thread safe)
9093
result=lv.async_call(lambda_:self.if_foreground(func,*args,**kwargs),None)
9194
returnresult

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp