#StackBounty: #python #python-3.x #wxpython wxPython application does not respond

Bounty: 50

I have a complex application, with a GUI that needs to dialogue with some I/O devices and with some WebAPI. I put my wx.Frame class in the main file, as I read that the GUI should be in the main thread to avoid freezing

if __name__ == "__main__":
    app = wx.App()
    frame = Window()
    app.MainLoop()

but still the GUI freezes very often, and sometimes it doesn’t show at all and a message saying "My_app is not responding" appears.
All the I/O and webAPI management is done in separate threads that are created by frame. The only GUI elements that are not in the main file are the pages that compose my notebook

from PageOne import PageOne
from PageTwo import PageTwo
from PageThree import PageThree

...

self.page1 = PageOne(self.nb)
self.page2 = PageTwo(self.nb)
self.page3 = PageThree(self.nb)

self.nb.AddPage(self.page1, "Page1")
self.nb.AddPage(self.page2, "Page2")
self.nb.AddPage(self.page3, "Page3")

All the communications between secondary threads and the GUI are done using wx.lib.newevent.NewEvent() in the main file and wx.PostEvent(self.parent, my_evt) in the threads.

I am using wxpython 4.1.1 and Ubuntu 20.04.2 LTS.

Any suggestion on how to prevent the GUI from not responding or freezing? Is maybe a better idea to use multiprocessing instead of multithreading? I know that threads are usually better for I/O applications…but is it still true in my case where the threads are all enless loops?

def run(self):
    while True:
        do_stuff()


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.