[PyKDE] twisted and PyQt4

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Fri Jun 2 10:43:09 BST 2006


On Friday 02 June 2006 09:37, scalet at yebu.de wrote:
> > On Thursday 01 June 2006 11:24, scalet at yebu.de wrote:

> > this approach on Windows. Your main thread normally spends its time
> > running
> > the Qt main loop, however on Windows it is quite legitimate for library
> > functions to briefly run their own message loop. Examples include standard
> > dialog boxes (file chooser, font chooser etc), MessageBox, and
> 
> I do not have any like problems, since I use qt in a very special
> (embedded) environment. No real qt-dialogs (but simulating my own),
> no message-boxes, not even mouse-handling, just hard-key handling.
> 
> But the problems you describe interested me, and so I did setup a
> message box. When this box comes up, incoming network traffic is
> processed normally (I got cyclic data packet into my app),

I guess you used a Qt message box, rather than a win32 message box.
(or maybe I am misremembering the exact details of this problem.... I 
certainly havent tested this recently)

> only
> if I _click_ into the caption bar on top of the message box, traffic
> processing stops as long as mouse button one is pressed. And that is
> bad.

You mean click and hold, to drag the window to a different position? Ive just 
tried this here (with ThreadedSelectReactor) and it did not block.

> BUT: Doesn't that mean, that twisted's asynchronous one-loop-only,
> single-threaded model in combination with _any_ graphical user
> interface (not just qt's) does not make that much sense.

It is probably not the best way to achieve the ultimate high performance 
network application, but there is no reason for it to suck. The gui libraries 
will be ensuring that the GUI remains adequately responsive, and there is no 
reason for the twisted reactor to be significantly less responsive than the 
gui. The reactor just needs to uses the same mechanisms to trigger twisted 
event handlers as Qt uses to trigger the gui event handlers.

On win32 this means message passing. Windows will be running a nested message 
loop using GetMessage/DispatchMessage while you are dragging the window 
around.

> I did not look into that yet, but at first it seems, that the
> major advantage of twisted's model (avoiding the hassle to
> synchronize between network-thread and gui-thread) is gone then.

No, its better than that! ThreadedSelectReactor lets your application code 
remain in that wonderfully simple single-threaded world. All twisted and PyQt 
application code runs in the Qt main thread.

The fact that it calls select in a second thread is an encapsulated 
implementation detail of the reactor class.


Hmmmm, there are some other issues scattered throughout the twisted and PyQt 
list archives, but I cant find any consolidated documentation. I should fix 
that.....

-- 
Toby Dickenson




More information about the PyQt mailing list