[Twisted-Python] wxpython issues

Bob Ippolito bob at redivi.com
Fri Apr 15 16:42:00 EDT 2005

On Apr 15, 2005, at 4:29 PM, Uwe C. Schroeder wrote:

> On Friday 15 April 2005 12:53, Glyph Lefkowitz wrote:
>> 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 ;-)
> There are certainly people better suited to respond to this, I'll try 
> anyways.
> The main problem with wx's mainloop is that wx uses the eventloops of 
> the
> platform dependant gui's. If you run wx on Linux with GTK2 it uses the 
> GTK2
> eventloop. On win it uses the windows loop etc. etc.  I'm not sure 
> this can
> be fixed - but as said, there are people who have more in-depth 
> knowledge
> about the issue. Wx is so popular because it works on all platforms in 
> a
> (mostly) consistent way. The only alternative I could think of is TK 
> or JAVA
> SWING (and both look really ugly). If you have to write a gui 
> application
> that has to run on multiple platforms and needs to look a bit more 
> modern,
> you have very few choices.
> Another idea here. Why not write a "wxreactor" that handles the 
> threading
> already and provides a "twisted consistent" API to the gui thread? 
> That way
> one could encapsulate any broken mainloop out there.
> Just a thought.

It would make perfect sense to provide an abstract reactor 
implementation that did the select/poll/etc. in a separate thread which 
sends an event to the mainloop to wake up the reactor... it could be 
used to interoperate with just about anything, pygame, wxPython, pygtk, 
Cocoa, etc. and would require very little work to "port".


More information about the Twisted-Python mailing list