Here are the examples of the python api twisted.internet.task.LoopingCall taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : memusage.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def engine_started(self):
self.crawler.stats.set_value('memusage/startup', self.get_virtual_size())
self.tasks = []
tsk = task.LoopingCall(self.update)
self.tasks.append(tsk)
tsk.start(self.check_interval, now=True)
if self.limit:
tsk = task.LoopingCall(self._check_limit)
self.tasks.append(tsk)
tsk.start(self.check_interval, now=True)
if self.warning:
tsk = task.LoopingCall(self._check_warning)
self.tasks.append(tsk)
tsk.start(self.check_interval, now=True)
3
View Complete Implementation : internet.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def startService(self):
service.Service.startService(self)
callable, args, kwargs = self.call
# we have to make a new LoopingCall each time we're started, because
# an active LoopingCall remains active when serialized. If
# LoopingCall were a _VolatileDataService, we wouldn't need to do
# this.
self._loop = task.LoopingCall(callable, *args, **kwargs)
self._loop.clock = _maybeGlobalReactor(self.clock)
self._loopFinished = self._loop.start(self.step, now=True)
self._loopFinished.addErrback(self._failed)
3
View Complete Implementation : test_task.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def testEveryIteration(self):
ran = []
def foo():
ran.append(None)
if len(ran) > 5:
lc.stop()
lc = task.LoopingCall(foo)
d = lc.start(0)
def stopped(ign):
self.astertEqual(len(ran), 6)
return d.addCallback(stopped)
3
View Complete Implementation : test_internet.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_startService(self):
"""
When L{TimerService.startService} is called, it marks itself
as running, creates a L{task.LoopingCall} and starts it.
"""
self.timer.startService()
self.astertTrue(self.timer.running, "Service is started")
self.astertIsInstance(self.timer._loop, task.LoopingCall)
self.astertIdentical(self.clock, self.timer._loop.clock)
self.astertTrue(self.timer._loop.running, "LoopingCall is started")
3
View Complete Implementation : posixbase.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def _checkLoop(self):
"""
Start or stop a C{LoopingCall} based on whether there are readers and
writers.
"""
if self._readers or self._writers:
if self._loop is None:
from twisted.internet.task import LoopingCall, _EPSILON
self._loop = LoopingCall(self.iterate)
self._loop.clock = self._reactor
# LoopingCall seems unhappy with timeout of 0, so use very
# small number:
self._loop.start(_EPSILON, now=False)
elif self._loop:
self._loop.stop()
self._loop = None
3
View Complete Implementation : __init__.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def __init__(self, crawler):
self.settings = crawler.settings
self.signals = crawler.signals
self.slots = {}
self.active = set()
self.handlers = DownloadHandlers(crawler)
self.total_concurrency = self.settings.getint('CONCURRENT_REQUESTS')
self.domain_concurrency = self.settings.getint('CONCURRENT_REQUESTS_PER_DOMAIN')
self.ip_concurrency = self.settings.getint('CONCURRENT_REQUESTS_PER_IP')
self.randomize_delay = self.settings.getbool('RANDOMIZE_DOWNLOAD_DELAY')
self.middleware = DownloaderMiddlewareManager.from_crawler(crawler)
self._slot_gc_loop = task.LoopingCall(self._slot_gc)
self._slot_gc_loop.start(60)
3
View Complete Implementation : test_task.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_deferredDeprecation(self):
"""
L{LoopingCall.deferred} is deprecated.
"""
loop = task.LoopingCall(lambda: None)
loop.deferred
message = (
'twisted.internet.task.LoopingCall.deferred was deprecated in '
'Twisted 16.0.0; '
'please use the deferred returned by start() instead'
)
warnings = self.flushWarnings([self.test_deferredDeprecation])
self.astertEqual(1, len(warnings))
self.astertEqual(DeprecationWarning, warnings[0]['category'])
self.astertEqual(message, warnings[0]['message'])
3
View Complete Implementation : test_task.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def testStopAtOnceLater(self):
# Ensure that even when LoopingCall.stop() is called from a
# reactor callback, it still prevents any subsequent calls.
d = defer.Deferred()
def foo():
d.errback(failure.DefaultException(
"This task also should never get called."))
self._lc = task.LoopingCall(foo)
self._lc.start(1, now=False)
reactor.callLater(0, self._callback_for_testStopAtOnceLater, d)
return d
3
View Complete Implementation : logstats.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def spider_opened(self, spider):
self.pagesprev = 0
self.itemsprev = 0
self.task = task.LoopingCall(self.log, spider)
self.task.start(self.interval)
3
View Complete Implementation : test_task.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_reprMethod(self):
"""
L{LoopingCall.__repr__} includes the wrapped method's full name.
"""
self.astertEqual(
repr(task.LoopingCall(TestableLoopingCall.__init__)),
"LoopingCall<None>(TestableLoopingCall.__init__, *(), **{})")