diff -r b075b3db3044 -r a409242121d5 scheduler.py --- a/scheduler.py Sun Jan 28 11:38:01 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -# -# Scheduler for Borgend -# -# This module simply provide a way for other threads to until a given time -# - -import time -import loggers -import dreamtime -from threading import Condition, Lock, Thread - -logger=loggers.get(__name__) - -class QueuedEvent: - def __init__(self, cond, name=None): - self.next=None - self.prev=None - self.name=name - self.cond=cond - - def __lt__(self, other): - raise NotImplementedError - - def insert_after(self, ev): - if not self.next or ev0: - logger.debug("Scheduler waiting %d seconds" % (timeout or (-1))) - self._cond.wait(timeout) - now = time.monotonic() - - logger.debug("Scheduler timed out") - - while self._list and self._list.when.monotonic() <= now: - ev=self._list - logger.debug("Scheduler activating %s" % (ev.name or "(unknown)")) - # We are only allowed to remove ev from list when ev.cond allows - with ev.cond: - self._list=ev.next - ev.unlink() - ev.cond.notifyAll() - - def _wakeup_callback(self): - logger.debug("Rescheduling events after wakeup") - with self._cond: - self._resort() - - def _wait(self, ev): - with self._cond: - self._insert(ev) - - # This will release the lock on cond, allowing queue manager (scheduler) - # thread to notify us if we are already to be released - ev.cond.wait() - - # If we were woken up by some other event, not the scheduler, - # ensure the event is removed - with self._cond: - self._unlink(ev) - - # cond has to be acquired on entry! - def wait_until(self, when, cond, name=None): - logger.debug("Scheduling '%s' in %s seconds [%s]" % - (name, when.seconds_to(), when.__class__.__name__)) - self._wait(ScheduledEvent(when, cond, name)) -