def consumer(m: Manager, uid: str): import os print(os.getpid(), "!") with m.open_reader_queue(uid) as q: for item in q: print(os.getpid(), "<-", item)
def produce(m: Manager, uid): with m.open_writer_queue(uid) as q: for i in range(5): logger.info("-> %d", i) q.put(i) time.sleep(0.3) q.put(None)
def run(): with Manager() as m: for i in range(3): uid = m.generate_uid(str(i)) m.spawn(consumer, uid=uid) m.spawn(producer, uid=uid) print("ok")
def run(): with Manager() as m: uid = m.generate_uid() m.spawn(worker, uid=uid) with m.open_writer_queue(uid) as q: for i in range(5): q.put(i) q.put(None)
def run() -> None: with Manager() as m: uid = m.generate_uid() m.spawn(consume, uid=uid) with m.open_writer_queue(uid) as q: for x in range(7): print(os.getpid(), "->", x) q.put(x)
def run(): with Manager() as m: uid = m.generate_uid("x") m.spawn(consumer, uid=uid) with m.open_writer_queue(uid, force=True) as q: for i in range(20): q.put(i) time.sleep(0.01) print("ok")
def run(): with Manager() as m: uid = m.generate_uid() m.spawn(produce, uid=uid) m.spawn(consume, uid=uid)
def worker(m: Manager, uid): import os with m.open_reader_queue(uid) as q: for item in q: print(os.getpid(), item)
def producer(m: Manager, uid: str): with m.open_writer_queue(uid, force=True) as q: for i in range(20): q.put(i) time.sleep(0.01) q.put(None)
def consume(m: Manager, uid: str) -> None: with m.open_reader_queue(uid) as q: for x in q: print(os.getpid(), "<-", x) time.sleep(0.1)