[Twisted-Python] Crash when using XmlRPC during reactor shutdown

David Anderson david.anderson at calixo.net
Sat Apr 29 11:29:47 MDT 2006


* David Anderson <david.anderson at calixo.net> [2006-04-29 17:10:06]:
> I have been experiencing a crash when trying to use the XmlRPC query
> subsystem while the reactor is shutting down.

After a bit more fiddling, I found a functional workaround.  The trick
is indeed to let the xmlrpc Deferred fully terminate *before* the
reactor continues the shutdown, instead of continuing the shutdown
within the Deferred callback.

With that in mind, the new stopService makes the RPC call, but
creates, stores and returns a different Deferred.  The RPC Deferred
gets a callback that calls reactor.callLater to schedule the firing of
the reactor's Deferred in 0 seconds.

That lets the xmlrpc deferred complete and clean up, and immediately
after the reactor schedules its own shutdown callback, and all is
well.

Here is the new stopService code:

****************************************************************
****************************************************************
    def stopService(self):
        def handle_success(res):
            log.msg("Unregistration successful, and reactor won't crash")
            reactor.callLater(0, self._def.callback, True)
        def handle_error(e):
            log.msg("Unregistration failed...")
            reactor.callLater(0, self._def.callback, False)

        log.msg("Calling XmlRPC backend (and crashing)")
        p = Proxy('http://natulte.net/pub/fgs/RPC2.php')
        d = p.callRemote('fgsd.register',
                         "00000000000000000000000000000000",
                         "bleh")
        self._def = defer.Deferred()
        d.addCallbacks(handle_success, handle_error)
        return self._def
****************************************************************
****************************************************************

Nevertheless, this feels more like a workaround than a complete
solution.  What do you all think?

- Dave.




More information about the Twisted-Python mailing list