def wait(self, till=None): """ THE ASSUMPTION IS wait() WILL ALWAYS RETURN WITH THE LOCK ACQUIRED :param till: WHEN TO GIVE UP WAITING FOR ANOTHER THREAD TO SIGNAL :return: """ if self.waiting: waiter = self.waiting.pop() waiter.go() try: waiter = Signal() self.waiting.appendleft(waiter) self.lock.release() (waiter | till).wait_for_go() return not not waiter finally: self.lock.acquire()
from __future__ import absolute_import from __future__ import division from __future__ import unicode_literals from thread import allocate_lock as _allocate_lock from time import sleep as _sleep from time import time as _time from pyLibrary.thread.signal import Signal from pyLibrary.times.dates import Date from pyLibrary.times.durations import Duration DEBUG = True INTERVAL = 0.1 next_ping = _time() done = Signal("Timers shutdown") done.go() class Till(Signal): """ TIMEOUT AS A SIGNAL """ enabled = False all_timers = [] locker = _allocate_lock() def __new__(cls, till=None, timeout=None, seconds=None): if not Till.enabled: return done