9 May 06:30
Poor man's LWP with PyQt
From: Sirtaj Singh Kang <sirtaj@...>
Subject: Poor man's LWP with PyQt
Newsgroups: gmane.comp.kde.india, gmane.comp.python.general.bangpypers
Date: 2009-05-09 04:31:43 GMT
Subject: Poor man's LWP with PyQt
Newsgroups: gmane.comp.kde.india, gmane.comp.python.general.bangpypers
Date: 2009-05-09 04:31:43 GMT
Hi all, I've been trying to find the path of least resistance to using cooperative multitasking in PyQt apps. There are a bunch of different options out there, including Twisted (The initial inqternet.py Qt support I wrote became the basis of the current Qt reactor, and it works great if you are using Twisted) and Kamaelia/Axon (I had a stab at implementing Qt event loop support for that - available here: http://sirtaj.net/projects/axonqt.py). However most of these approaches require you to commit to frameworks that are likely to shape the implementation of the rest of your app. The two recommended ways to doing this sort of thing in Qt/C++ are: 1) use QTimer with a timeout of 0 to call some function. 2) In a long-running loop, call processEvents to allow other events to be processed to keep the GUI interactive. ...and that's all she wrote, since C++ doesn't really allow many options besides multithreading. With the yield keyword, however, we can get the same kind of cooperative multitasking that we had back in 1991 with Visual Basic 1.0 (yay!). This is the approach that Axon uses. Using the QTimer method above, a handful of lines of code gets us this in PyQt without having to use a larger framework: ---------------------------------------------------------------(Continue reading)
RSS Feed