[Python-Dev] Threading in the Standard Library Tour Part II

Michel Pelletier michel at dialnetwork.com
Mon Aug 16 13:35:06 CEST 2004


> (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.)

What if asyncore encapsulated the socket map in a selection object (like
Java NIO) instead of a thread-global, module-level dictionary?.
Selections could then be made by calling methods on an object (again,
like NIO's select() (blocking), selectNow() (nonblocking) and
select(timeout)).

This doesn't really address the wx/event granularity issue, but it would
reduce the thread madness considerably and allow programmers to see
beyond asyncore's mainloop() by rolling their own, possible one taking
into consideration other event loops like GUIs.

Another benefit would be more than one selection loop per process,
allowing multiple threads to handle multiple selection sets.

-Michel


More information about the Python-Dev mailing list