I have an app with several screens and a Nav Drawer with items to make a screen current
I have just added some code that refences screen s & is called from inside a function called by another thread another thread. The function is decorated with @mainthread since it needs to update GUI
Everything works, but after the threaded code has been called (& finished) then using the nav drawer to change currentscreen takes 25 seconds - but just the first time!
After it succeeds, subsequent selections using the Nav are immediate.
From debugging and logging it appears that Kivy is just not acting on my click for 25 seconds - i.e clicking the nav does nothing in Pycharm - for 25 seconds
Note that running my new code directly ( not called from another thread) runs immediately and there is no 25 second delay using the nav.
I suspect that something is going wrong with the thread transition - is 25 seconds a magic number? Any ideas?
t = Thread(target=self.sync_thread)
t.daemon = True
t.start()
def sync_thread(self):
# runs on new thread
result = False
try:
# run authenticate in sync pattern since it must succeed before proceeding
timeout = 3
result = comm.server_authenticate()
if result:
result = comm.sync()
except Exception as e:
logger.error(f'Something went wrong e= {e}')
result = False
# call on_sync_end which runs back on main GUI thread
self.on_sync_end(result)
@mainthread
def on_sync_end(self, result):
# decorator makes this run on main GUI thread to close animation
try:
self.ids.spinner.active = False
self.ids.updatelabel.opacity = 0
self.update_stats()
logger.debug('sync ended')
# new code that cause the 25 secound pause
self.updatelists()
if not result:
self.ok_popup('Cannot reach server - check your Internet connection')
except Exception as e:
logger.error(F'On sync end: {e}')
# this is what was added that causes the 25 second delay
def updatelists(self):
# repopulate Assets MDlists
als = self.manager.get_screen('AssetListScreen')
als.repopulate_assets()
ils = self.manager.get_screen('InspectListScreen')
ils.repopulate_assets()