wxpythonpython-multithreadingwxnotebook

wxpython notebook panel hangs when threads are running


I am trying to develop a gui using wxpython that has 3-4 notebook panels and one of these panels (master panel) calls another python script called abc.py. In this abc.py i am running several(>10) threads simultaneously. When I hit run button on master panel it starts these simultaneous threads of abc.py script. The problem I am facing here is my wxpython notebook gets hang up for time between: "when I hit run button and upto all the threads are joined". For this period I am not able to control other buttons on my panel nor am i able to switch between panels. My window gets freezed up for this period of time. What could be the problem? If anyone could guide me to proper path to avoid this issue then i will really be very grateful. Thank you..!!!


Solution

  • You will also need to wrap the call to abc.py (with popen, I suppose) into a thread, otherwise the GUI will block. When the process in the external script is collecting its answer, you have to get it back in a thread-safe way (important!) to wxPython.

    A better way would be to import from abc.py, if that is possible and spin the imported objects in the long running thread.

    For an explanation how to communicate back thread-safe see the wxPython wiki. I personally find the last example the easiest to understand and implement.