My KIVY-GUI freezes randomly and im not too sure why. I change a couple of widgets from python-side (i.e. enabling checkboxes, changing textinput texts and so on), sometimes from loops (i.e. enabling 6 checkboxes one after another). I think the freeze happens mainly when i disable a lot of widgets at once, however it also happens when changing only one widget. By going to the shell window and pressing CTRL+C i can unfreeze the GUI again. Sometimes the GUI then crashes with the following error:
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "GUI_MELC.py", line 637, in <module>
GUI_MELC().run()
File "C:\Python37\lib\site-packages\kivy\app.py", line 855, in run
runTouchApp()
File "C:\Python37\lib\site-packages\kivy\base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "C:\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
self._mainloop()
File "C:\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
EventLoop.idle()
File "C:\Python37\lib\site-packages\kivy\base.py", line 339, in idle
Clock.tick()
File "C:\Python37\lib\site-packages\kivy\clock.py", line 563, in tick
current = self.idle()
File "C:\Python37\lib\site-packages\kivy\clock.py", line 543, in idle
usleep(1000000 * sleeptime)
File "C:\Python37\lib\site-packages\kivy\clock.py", line 727, in usleep
_usleep(microseconds, self._sleep_obj)
File "C:\Python37\lib\site-packages\kivy\clock.py", line 405, in _usleep
_kernel32.WaitForSingleObject(obj, 0xffffffff)
KeyboardInterrupt
Some sample code of how i disable widgets (this is probably the most clock-intensive, if you can call it like that):
guiElements = []
temp=['redAll', 'greenAll', 'blueAll']
guiElements.extend(temp)
for i in range(6):
temp1='red'+str(i)
temp2='gre'+str(i)
temp3='blu'+str(i)
temp4='red'+str(i)+'Val'
temp5='gre'+str(i)+'Val'
temp6='blu'+str(i)+'Val'
tempList=[temp1, temp2, temp3, temp4, temp5, temp6]
guiElements.extend(tempList)
def disableMainBoxGUI(self, status):
#self.getGUIElements()
for i in self.guiElements:
self.ids[i].disabled = status
Is there a way to avoid freezing of the GUI? Do i have to add time.sleep(XX) or something?
Just some simple advice- learn to use threading. It's not that complicated and it will help a lot for running through long loops. I suggest reading this to familiarize yourself. Threading will speed up your applications and eliminate GUI freezing. I use a ThreadPoolExececutor in almost every one of my projects, but all you need is a simple daemon thread. Hope this helped!