Example #1
0
 def prepend(self, x):
     # NOTE: this is heavy, use judiciously
     if self.shut:
         raise e_exc.QueueShutdown()
     with self.lock:
         self.items.insert(0, x)
         self.event.set()
Example #2
0
 def __iter__(self):
     if self.shut:
         raise e_exc.QueueShutdown()
     try:
         while True:
             ret = self.get()
             yield ret
     except e_exc.QueueShutdown as e:
         pass
Example #3
0
    def get(self, timeout=None):
        self.last = time.time()
        with self.lock:
            if self.items:
                return self._get_items()

            if self.shut:
                raise e_exc.QueueShutdown()

            # Clear the event so we can wait...
            self.event.clear()

        self.event.wait(timeout=timeout)
        if self.shut:
            raise e_exc.QueueShutdown()
        with self.lock:
            self.last = time.time()
            if not self.items and self.shut:
                raise e_exc.QueueShutdown()
            return self._get_items()
Example #4
0
    def get(self, timeout=None):
        start = time.time()
        self.last = start

        while True:
            if self.shut:
                raise e_exc.QueueShutdown()

            with self.lock:
                if self.items:
                    return self.items.popleft()

                # Clear the event so we can wait...
                self.event.clear()

            deltat = None
            if timeout:
                deltat = max(0, timeout - (time.time() - start))

            if not self.event.wait(timeout=deltat):
                return None
Example #5
0
 def extend(self, x):
     if self.shut:
         raise e_exc.QueueShutdown()
     with self.lock:
         self.items.extend(x)
         self.event.set()
Example #6
0
 def prepend(self, x):
     if self.shut:
         raise e_exc.QueueShutdown()
     with self.lock:
         self.items.appendleft(x)
         self.event.set()
Example #7
0
 def put(self, item):
     if self.shut:
         raise e_exc.QueueShutdown()
     self.append(item)