在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