diff -r 1fd6814a29fc -r 6cfe6a89e810 repository.py --- a/repository.py Wed Jan 24 22:23:51 2018 +0000 +++ b/repository.py Thu Jan 25 22:34:55 2018 +0000 @@ -3,15 +3,18 @@ # import weakref +import borgend from scheduler import QueueThread, QueuedEvent +logger=borgend.logger.getChild(__name__) + class FIFOEvent(QueuedEvent): def __init__(self, cond, name=None): self._goodtogo=False super().__init__(cond, name=name) def __lt__(self, other): - return True + return False class FIFO(QueueThread): def __init__(self, **kwargs): @@ -24,8 +27,9 @@ if ev: # We can only remove ev from the list when ev.cond allows with ev.cond: - ev._goodtogo=True - ev.cond.notifyAll() + if not ev._goodtogo: + ev._goodtogo=True + ev.cond.notifyAll() self._cond.wait() # Termination cleanup @@ -43,19 +47,22 @@ with self._cond: self._insert(ev) - goodtogo=False - terminate_=False - while not goodtogo and not terminate_: - # 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() - with ev.cond: - goodtogo=ev._goodtogo - with self._cond: - terminate_=self._terminate + # This will release the lock on cond, allowing queue manager (scheduler) + # thread to notify us if we are already to be released + logger.debug("%s:Queuing %s", self.name, ev.name or 'UNKNOWN') + ev.cond.wait() try: - if not terminate_: + if ev._goodtogo: + logger.debug("%s:Executing %s", self.name, ev.name or 'UNKNOWN') + # + # TODO: action() has to unlink on finish; so should maybe + # use weak references to event. + # Or we have to make action take all the time, so make the + # stdout thread. + # OR: Easiest to just move finish-waiting into __launch_check + # instead of at the outer level of the main loop. + # action() finally: with self._cond: @@ -63,6 +70,8 @@ # Let _fifo_thread proceed to next action self._cond.notify() + return ev._goodtogo + class Repository(FIFO): def __init__(self, name): super().__init__(name = 'RepositoryThread %s' % name)