twistedタイミング処理(task.LoopingCall)(factory内)

875 ワード

factory内での使用
"""    
lc = task.LoopingCall(fun),   fun    ,    functools.partial   (fun2 = partial(fun, param1,[...])   task.LoopingCall(fun2))
lc.start(interval)
lc.stop()
"""
from twisted.internet import protocol, task

class UserClient(protocol.ReconnectingClientFactory):
    maxDelay = 10
    
    def __init__(self, options):
        self.options = options

    def startFactory(self):
        def doit():
            self.queried = set() #     queried
        self.lc = task.LoopingCall(doit)
        self.lc.start(3600) #    1h

    def stopFactory(self):
        self.lc.stop()

    def buildProtocol(self, addr):
        p = UserProtocol(self.options)
        p.factory = self
        return p