[PyKDE] Keeping the GUI from freezing
Tony Cappellini
cappy2112 at gmail.com
Tue Feb 13 20:32:11 GMT 2007
I started out using Popen() in a thread, and that worked fine.
The author of the app that I'm calling then decided to use the logging
module, and I could not capture the output any longer.
He then suggested a really ugly hack. It works, but it's not nice.
I"m between a rock & a hard place. He doesn't want to write his module
so I can just import it, and call his main. Actually, I think the use
of the logging module is more of an issue than not being able to just
import his module and call his main. It has something to do with
globals not really being global across all modules- don't recall his
explanation at the moment.
Anyway, this is what I had to resort to- because of his use of the
logging module
self._script = open('TargetApp.py').read()
exec self._script in globals()
logging = globals()['logging']
filelog = logging.FileHandler('test.log','w')
logging.getLogger('').addHandler(filelog)
I then have to open test.log to get the ouput, to display it in a textedit box.
Yes, I know it's not safe, and it's ugly, but I'm stuck. It works
So - before this gets called, I need to setup a timer to refresh the
GUI at regular intervals, I'm just not sure how. I understand the
timer, I just don't know what to call in QT's framework.
Paul Giannaros ceruleanblaze at gmail.com
Tue Feb 13 19:19:46 MET 2007
>
> Does anyone have a Python example of how to use a Thread to keep a gui
> from becoming unresponsive?
Well, before you turn to threads I'd suggest that there are far simpler ways
to go about what you want to do. There are may ways to start a process
asynchronously so that the GUI remains responsive as usual. You can use the
os.popen function, for example; or the subprocess module; or Qt's QProcess.
More information about the PyQt
mailing list