[Twisted-Python] Reconnecting PB Client
Does anyone have some example code for building a reconnecting PB client? This is what I have now: from twisted.spread import pb from twisted.internet import reactor from twisted.python import util events = pb.PBClientFactory() reactor.connectTCP("localhost", 8789, events) queue = events.getRootObject()
On Jul 14, 2006, at 4:40 AM, Don Smith wrote:
Does anyone have some example code for building a reconnecting PB client?
I'm trying to do something similar, and not sure where to begin. The docs show how to make a reconnecting client when you define your own protocol, which might help as a starting point: http://twistedmatrix.com/projects/core/documentation/howto/clients.html Does anyone else have any idea how to do this with Perspective Broker? Robert
On Jul 14, 2006, at 4:40 AM, Don Smith wrote:
Does anyone have some example code for building a reconnecting PB client?
I do something like this: class Foo(object): # ... def connect(self): factory = FooMgrFactory() reactor.connectTCP(host, port, factory) return factory.getRootObject().addCallback (self._connected).addErrback( self._catchFailure) def _connected(self, rootObj): self.rootObj = rootObj rootObj.notifyOnDisconnect(self._disconnected) def _disconnected(self, rootObj): self.rootObj = None self.connected = False self.timer = reactor.callLater(defaultTimerDelay, self.connect) def doRemoteOp(self): try: if self.rootObj: self.rootObj.callRemote("foo", arg).addCallback (self.fooreturn) else: self.timer = reactor.callLater(defaultTimerDelay, self.connect) except pb.DeadReferenceError, e: self.rootObj = None self.timer = reactor.callLater(defaultTimerDelay, self.connect) Please advise if this is not a preferred method. Regards, Brendan
participants (3)
-
Brendan Boerner
-
Don Smith
-
Robert Gravina