[Twisted-Python] service takedown (one newbie to other newbies, methinks)

Bill la Forge laforge49 at yahoo.co.in
Sat May 22 03:15:50 MDT 2004


GrumpBrumpGrumpGrump

2 bug fixes and one repaired omission later...
I MIGHT just have something I can use to implement
bsddb services. ;-)))) --b

from twisted.application import service
from twisted.internet import reactor
from twisted.python import log

class TieredService(service.MultiService):
    def __init__(self,stopOnStartFailure=False):
        service.MultiService.__init__(self)
        self.stopOnStartFailure=stopOnStartFailure
    def __getstate__(self):
        d = service.Service.__getstate__(self)
        for attr in self.volatile:
            if d.has_key(attr):
                del d[attr]
        return d
    volitile=['shutdownTrigger','started']
    def startService(self):
        self.started=[]
        for svc in self:
            try:
                svc.startService()
            except:
                log.err()
                self.cancelService()
                return
            else:
                self.started.append(svc)
        self.shutdownTrigger=reactor \
            .addSystemEventTrigger(
               
'before','shutdown',self.cancelService)
        reactor.callWhenRunning(self.nowRunning)
        service.Service.startService(self)
    def nowRunning(self):
        reactor.removeSystemEventTrigger(
            self.shutdownTrigger)
        self.shutdownTrigger=None
        self.started=None
    def cancelService(self):
        service.Service.stopService(self)
        for svc in self.started[::-1]:
            svc.cancelService()
        if self.stopOnStartFailure:
            reactor.stop()


=====
Bill la Forge
http://www.geocities.com/laforge49/

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/




More information about the Twisted-Python mailing list