def _run(self):
"""Run the wrapped function periodically"""
try:
while True:
ts = time.time()
if self.last_timestamp + self.interval_secs <= ts:
self.last_timestamp = ts
try:
self.f(*self.args, **self.kwargs)
except gevent.GreenletExit:
# We are notified to exit.
raise
except BaseException as e:
# We ignore other exceptions.
log.error("Exception %s caught in Periodical %s " % (
repr(e), self.name))
# sleep until the time for the next run.
sleep_secs = self.last_timestamp + self.interval_secs \
- time.time()
if sleep_secs < 0:
sleep_secs = 0
gevent.sleep(sleep_secs)
except gevent.GreenletExit:
log.info("Periodical %s stopped." % self.name)
评论列表
文章目录