[Twisted-web] Custom __del__ not run

Rasjid Wilcox rasjidw at openminddev.net
Tue Jul 26 03:49:27 MDT 2005

Hello again.

I have my xmlrpc class that I am running in twisted.  I want it to do some 
cleaning up when it is finished, and so I have defined a custom __del__ 

However, when mixed with a looping call, it never gets called.  Sample code 
below.  Remove the two lines starting with self.looping, and it all works as 
expected.  Put them in, and the custom __del__ is not called.

Is this a bug in twisted?  Or have I broken some twisted rule about using 
__del__ procedures?  Is there some other way of saying 'when you have stopped 
the reactor, do foo', that twisted would be happy with?

Any suggestions welcome.  :-)



from twisted.web import xmlrpc

import xmlrpclib
from twisted.internet import reactor, task

class Hello(xmlrpc.XMLRPC):
    def __init__(self):
        print 'Init class Hello'
        # the following two lines cause the custom __del__
        # function to never be called
        self.looping = task.LoopingCall(self.foo)
    def __del__(self):
        print 'Tidy up class Hello'
    def foo(self):
        print 'foo!'
    def xmlrpc_hello(self):
        """Return 'hello, world'."""
        return 'hello, world!'
    def xmlrpc_quit(self):
        reactor.callLater(0.1, reactor.stop)
        return 'Shutting down server'

def main():
    from twisted.web import server
    r = Hello()
    reactor.listenTCP(7080, server.Site(r), interface = '')

if __name__ == '__main__':

Rasjid Wilcox
Melbourne, Australia (UTC +10 hrs)

More information about the Twisted-web mailing list