def wait(self, timeout=None):
        if not self._is_owned():
            raise RuntimeError("cannot wait on un-acquired lock")
        waiter = Lock()
        waiter.acquire()

        self.__waiters.append(waiter)
        saved_state = self._release_save()
        try: # restore state no matter what (e.g., KeyboardInterrupt)
            if timeout is None:
                waiter.acquire()
            else:
                # Balancing act: We can't afford a pure busy loop, so we have
                # to sleep; but if we sleep the whole timeout time, we'll be
                # unresponsive. The scheme her sleeps very little at first,
                # longer as time goes on, but never longer than 20 times per
                # second (or the timeout time remaining).
                endtime = _time() + timeout
                delay = 0.0005 

                while True:
                    gotit = waiter.acquire(0)
                    if gotit:
                        break
                    remaining = endtime - _time()
                    if remaining <= 0:
                        break

                    # The delay is the least between 2x the delay, the time remaining and/or .05
                    delay = min(delay * 2, remaining, 0.05)

                    _sleep(delay)

                if not gotit:
                    try:
                        self.__waiters.remove(waiter)
                    except __HOLE__:
                        pass
        finally:
            self._acquire_restore(saved_state)
dataset/ETHPy150Open ooici/pyon/pyon/util/threading.py/Condition.wait