[Twisted-Python] wxpython issues

Glyph Lefkowitz glyph at divmod.com
Fri Apr 15 15:53:16 EDT 2005

Shawn Church wrote:

> I have looked at implementations of Soap,  CORBA,  and Pyro,  none of which
> have really statisfied me.  I thought that by using the PB interface of
> twisted,  along with a SSL connection,  I could achieve all of my objectives
> fairly simply -- once I worked out the details I was able connect,  login,
> and transfer data with very little code.

All of this, and more, is possible with Twisted.

> I fully realize that if I want to write a GUI application that depends upon
> arbitrary responses from the server (i.e. a chat client to use your example)
> then my approach will not work.

That was an example of where the brokenness would be instantly visible 
to any user of your program.  Internally Twisted makes many assumptions 
about the reactor generally being running which may cause you lots of 
little surprises if you use the technique you've proposed.

> What I want to do is have my clients request
> data from the server and wait till the data is ready (seems prettty simple
> :-))

the Twisted way is to invert it so that rather than saying "Wait until Y 
is done, then do X", you say "Do X when Y is done."  Among other things, 
this approach lets you do more than one thing at a time.  For example, 
you might want to put a "cancel" button in your UI if your application 
has to run over the internet.  Responding to the cancel button at the 
same time as waiting for a request's response is a second thing, so you 
need to be worried about concurrency even in simple applications.

 > Twisted seems to do what I want (assuming I can interface with wx),
> but if you can point to another package please let me know.

I would point you at gtk, Tkinter, or win32api, not an alternative to 
Twisted :).  wx is the problem here: its mainloop is badly broken, on 
all platforms.  Twisted works fine.  The easiest fix, if wx is a genuine 
requirement, is to run the wx main loop in a Twisted thread, using 
callInThread, so that the Twisted event loop (i.e. the one that isn't 
horribly broken) is "in charge".

I believe that future releases of wx are fixing this issue, as well, 
since you're far from the first person to have complained about it.  I 
hope that this happens soon, since despite its many flaws wx is very 
popular in the Python community.

P.S.: If I seem negative towards WX, it is only because my _only_ use of 
it is answering this same question over and over again.  I'm sure it has 
some positive points too, but I never discover them, because for my own 
development projects "non-broken mainloop" is criterion #1 for the GUI 
framework ;-)

More information about the Twisted-Python mailing list