def run(self): pq = PriorityQueue() for q in self.queues: t = q.reset() pq.push(t, q) while not pq.empty(): t = max(t, pq.key()) q = pq.value() pq.pop() next_t = q.process(t) if next_t >= 0: pq.push(next_t, q) return t