The wxreactor works fairly well, but it’s a bit dodgy and heavy network activity can cause the GUI to appear unresponsive because both the network and GUI event loops are one and the same in this case.
Henning’s comment about the threadingreactor is about right. That allows network and GUI to go about thier business without undue conflict and is fairly safe. As said, be careful how you post events from the GUI to the network, and vice-versa. wx.CallAfter() is a simple means to add events to the wx event loop, and reactor.callLater() is a simple means to do so for the network side. NEVER directly reference between the two event loops and race conditions will at least be minimized.
I always use dispatcher messages to send events and don’t care if a wx or twisted object processes them.
I use PyDispatcher too, but I have special form of calling it if I want to receive events in my GUI. That's because dispatcher may be called from another thread and when the GUI receives the event immediately, it will wreak havoc. The class I use this for is:
class SafeGUIEventWrapper:
callbacks =
def __init__(self, func):
self.func = func
# this is for the dispatcher weakref stuff, could also use the 'weak' param of dispatcher.connect, but I don't want that
SafeGUIEventWrapper.callbacks.append(self)