def push(self, request, key=None): if not key: key = self.key logger.debug("push %s ### %s", key, request) data = self._encode_request(request) if key in self.k2queue: self.k2queue[key].push(data) else: if lock.acquire(): try: if key not in self.k2queue: queue = FifoMemoryQueue() queue.push(data) self.k2queue.update({key: queue}) else: self.k2queue[key].push(data) finally: lock.release()
def test_isinstance(self): assert not isinstance(1, BaseQueue) assert not isinstance([], BaseQueue) assert isinstance(DummyQueue(), BaseQueue) assert isinstance(FifoMemoryQueue(), BaseQueue) assert isinstance(LifoMemoryQueue(), BaseQueue) for cls in [ FifoDiskQueue, LifoDiskQueue, FifoSQLiteQueue, LifoSQLiteQueue ]: queue = cls(self.tempfilename()) assert isinstance(queue, BaseQueue) queue.close()
def test_threading(self): self.q = FifoMemoryQueue() thread_cnt = 1000 self.itemcnt = 1000 self.sum = 0 threads = [] for i in xrange(thread_cnt): t = threading.Thread(target=self.push_and_pop) threads.append(t) t.start() for t in threads: t.join() self.assertEqual(thread_cnt * self.itemcnt * (self.itemcnt - 1) / 2, self.sum)
def queue(self): return FifoMemoryQueue()