示例#1
0
文件: utils.py 项目: javawizard/stm
 def _():
     if function():
         return
     elif stm.elapsed(timeout_after, timeout_at):
         raise Timeout
     else:
         stm.retry()
示例#2
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()
示例#3
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 not block:
             raise Empty
         elif stm.elapsed(timeout):
             raise Timeout
         else:
             stm.retry()
     else:
         item = self._var.get()
         self._var = item.next
         self._read += 1
         return item.value