Example #1
0
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)
Example #2
0
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)
Example #3
0
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")
Example #4
0
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)
Example #5
0
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)
Example #6
0
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")
Example #7
0
def run():
    with Manager() as m:
        uid = m.generate_uid()
        m.spawn(produce, uid=uid)
        m.spawn(consume, uid=uid)
Example #8
0
def worker(m: Manager, uid):
    import os

    with m.open_reader_queue(uid) as q:
        for item in q:
            print(os.getpid(), item)
Example #9
0
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)
Example #10
0
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)