Ejemplo n.º 1
0
 def _():
     if function():
         return
     elif stm.elapsed(timeout_after, timeout_at):
         raise Timeout
     else:
         stm.retry()
Ejemplo n.º 2
0
def wait_for_true(var):
    """
    Waits for the specified var to become True (or any true value), retrying if
    it's False (or any non-true value).
    """
    if not var.get():
        stm.retry()
Ejemplo n.º 3
0
 def wait_for_new_state(self, last_state, names):
     if not self.running:
         raise StopException
     server_state = self.get_state()
     new_state = TDict()
     for k in names:
         new_state[k] = server_state.get(k, 0)
     if new_state == last_state:
         retry()
     else:
         last_state.clear()
         last_state.update(new_state)
         return new_state
Ejemplo n.º 4
0
 def task():
     # See if we have any tasks to run.
     if self.current_task:
         # We do. Mark ourselves as no longer free.
         return self.current_task
     # No tasks yet, so see if we've been idle for more than
     # self._keep_alive seconds.
     if stm.elapsed(self.pool._keep_alive):
         # We have, so decrement the number of free and live threads
         # and then die.
         self.pool._live_threads -= 1
         # Note that we don't access _free_threads until when we're
         # actually going to die, so we won't ever resume from
         # retrying just because another thread became free.
         del self.pool._free_threads[self]
         return None
     # We haven't, so retry.
     stm.retry()
Ejemplo n.º 5
0
 def get(self, block=True, timeout=None):
     """
     Removes and returns the next available item from this endpoint.
     
     If block is False and there aren't any items currently available on
     this endpoint, Empty will be raised. If block is True, this function
     retries. If timeout is specified and there still aren't any items
     available on this endpoint after that many seconds, Timeout will be
     raised.
     """
     if self._var.get() is None:
         if block:
             stm.retry(resume_after=timeout)
             raise Timeout
         else:
             raise Empty
     else:
         item = self._var.get()
         self._var = item.next
         return item.value
Ejemplo n.º 6
0
 def get(self, block=True, timeout=None):
     """
     Removes and returns the next available item from this endpoint.
     
     If block is False and there aren't any items currently available on
     this endpoint, Empty will be raised. If block is True, this function
     retries. If timeout is specified and there still aren't any items
     available on this endpoint after that many seconds, Timeout will be
     raised.
     """
     if self._var.get() is None:
         if block:
             stm.retry(resume_after=timeout)
             raise Timeout
         else:
             raise Empty
     else:
         item = self._var.get()
         self._var = item.next
         return item.value
Ejemplo n.º 7
0
 def _():
     if not default_event_loop._endpoint.is_empty:
         stm.retry()