From: Tony C. <cap...@gm...> - 2007-11-17 17:37:17
|
I've found the problem. My call to wx.SafeYield() didn't include self (which is an instance of the GUI class) When I changed the call to wx.SafeYield(self) the GUI no longer freezes while class2 is processing files. thanks On Nov 17, 2007 8:41 AM, Kevin Altis <al...@se...> wrote: > In general, you can't do anything long running in an event handler or > it will lock your program up as you found. In your case, you should > take a look at some of the samples and documentation that cover the > Python thread and Queue modules. Queue is guaranteed to be thread- > safe so that is what you use to communicate between your GUI thread > and the thread that is during your long-running work. > > http://pythoncard.sourceforge.net/timers-threads.html > > Samples that use threads are: chat, jabberChat, webgrabber, and > webserver. > > You'll probably find doing some searches for code snippets and topics > with the findfiles tool useful. > > http://pythoncard.sourceforge.net/findfiles.html > > Simply set the directory to search to your copy of PythonCard and > then look for appropriate topics like thread and Queue. > > ka > > > On Nov 16, 2007, at 4:17 PM, Tony Cappellini wrote: > > > I've got 2 classes in my Pythoncard program. > > > > The GUI is handled in class1 and some file processing is handled in > > class2. > > > > Class2 executes an external program in a thread, and loops waiting for > > the thread to finish. > > In that loop, I call a method in class1 which calls wx.safeYield(). > > > > The external program is processing some text files, and the GUI lets > > the user choose which files to process and passes those files as args > > to the external program. > > > > While the gui is looping passing a new filename to the program, my > > Pythoncard GUI is unresponsive. That is, I cannot move it with the > > mouse, nor maximize/minimize it. > > > > Class1 passes a callback to class2 to allow class2 to execute a > > callback which calls wx.SafeYield. That callback can be seen below > > (guiCallback) > > > > This is the method in class2 which executes the external program, > > in a thread > > > > threadHandle = ManagedThread(ExecutePipedCommand, cmdLine) > > > > while not threadHandle.IsDone(): > > guiCallback() > > time.sleep(.10) > > > > > > ExecutePipedCommand() is just a wrapper class for os.popen() > > ManagedThread() is just a wrapper for the functionality in the > > threading module > > > > How should I proceed to keep my pythoncard gui from freezing? > > > > Thanks > > > |