[Twisted-Python] PB SturdyRef issue

Andrew Bennetts andrew-twisted at puzzling.org
Thu Jun 23 21:58:10 EDT 2005

On Thu, Jun 23, 2005 at 04:09:31PM -0600, Bruce Mitchener wrote:
> I'm using something similar in style to a pb.SturdyRef and have run 
> across a problem with it:
> While it handles pb.DeadReferenceError, it doesn't handle the 
> pb.PBConnectionLost that can come back as an errback from the callRemote.
> Is there some way that I can juggle deferreds so that the caller can get 
> the response from the server after I reconnect and re-try like what 
> happens in the case of pb.DeadReferenceError?
> It doesn't seem like I can just attach an errback to the deferred and in 
> that errback, do a failure.trap(pb.PBConnectionLost) and then do 
> something to bind a new deferred into the callback chain ...
> Is there something that can happen magically by returning a new deferred 
> from the errback that successfully traps the PBConnectionLost?

If you return a Deferred from a callback/errback, the outer Deferred will
wait for the inner Deferred to fire before continuing with its callback
chain.  It sounds like this is the magic you are looking for.

So here's one way to take advantage of that:

def sturdyRemoteCall(foo, *args, **kwargs):

    d = ...  # whatever you do to make the remote call, handle
             # DeadReferenceErrors, etc.

    def retryOnConnectionLost(failure):
        return sturdyRemoteCall(foo, *args, **kwargs)

    return d


More information about the Twisted-Python mailing list