[Twisted-Python] Reconnecting PB Client
Brendan Boerner
bboerner at rgmadvisors.com
Wed Sep 12 08:03:04 MDT 2007
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
More information about the Twisted-Python
mailing list