[Python-Dev] Threading in the Standard Library Tour Part II (original) (raw)
Anthony Baxter anthony at interlink.com.au
Mon Aug 16 17:52:45 CEST 2004
- Previous message: [Python-Dev] Threading in the Standard Library Tour Part II
- Next message: [Python-Dev] Threading in the Standard Library Tour Part II
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bob Ippolito wrote:
But in those cases, Twisted only needs the mainloop to do two things: fire timers, watch file descriptors. It's possible to write a reactor for many or most GUIs that does that while still remaining single threaded (as far as Python is concerned). For GUIs that don't natively "watch sockets" as part of their runloop, you can start a thread that does that and only that and send asynchronous notifications to the GUI mainloop (which is what Cocoa/CoreFoundation does behind your back with their networking APIs).
Unfortunately in the wx case, the timer granularity sucks. The wx docs guarantee "no worse than 1s granularity". It's not that bad, but on Windows at least, it's pretty terrible - at best, only 20-30Hz. I'm depressingly sure that there's other GUI toolkits with similar levels of suck.
(Short (off-topic) summary - there's two ways to make the twisted and wx event loops cooperate - either the wx event loop runs everything, and fires timers to let the twisted event loop do it's thing - see above. The second is to let the twisted event loop regularly call the wx event loop to let it iterate any outstanding events. When a popup or menu comes up, wx creates a new sub-event-loop and takes control until that's dismissed... so we're back to needing to run the two event loops alongside each other. And yes, Tim's comment about insanity resulting from using asyncore and threads together also apply to twisted - the only sane way to do it is to have all the event loop stuff handled in the same thread. Madness follows, otherwise.)
Anthony
-- Anthony Baxter <anthony at interlink.com.au> It's never too late to have a happy childhood.
- Previous message: [Python-Dev] Threading in the Standard Library Tour Part II
- Next message: [Python-Dev] Threading in the Standard Library Tour Part II
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]