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()
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
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()
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
def extend(self, x): if self.shut: raise e_exc.QueueShutdown() with self.lock: self.items.extend(x) self.event.set()
def prepend(self, x): if self.shut: raise e_exc.QueueShutdown() with self.lock: self.items.appendleft(x) self.event.set()
def put(self, item): if self.shut: raise e_exc.QueueShutdown() self.append(item)