wxPython and Twisted

Nachricht

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. :wink:

(http://pydispatcher.sourceforge.net/)

Best regards,
Henning Hraban Ramm
Südkurier Medienhaus / MediaPro
Support/Admin/Development Dept.

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)

     def __call__(self, *args, **keys):
         code = self.func.func_code

         callargs = code.co_argcount
         funcargs = code.co_varnames[:callargs]
         newKeys = dict( [ (key, value) for key, value in keys.items() if key in funcargs] )

         wx.CallAfter(self.func, *args, **newKeys)

and I use it like this in my main frame:

dispatcher.connect( SafeGUIEventWrapper(self.SetConnected), signal = Events.ConnectionStatusChanged )

-Matthias

···

Am Mon, 26 Sep 2005 20:12:47 +0200 hat <Henning.Ramm@mediapro-gmbh.de> geschrieben:

I always use dispatcher messages to send events and don't care if a wx or twisted object processes them. :wink:
(http://pydispatcher.sourceforge.net/)