| | |
| | | |
| | | __queue = queue.Queue() |
| | | |
| | | |
| | | def read(pipe): |
| | | while True: |
| | | if not __queue.empty(): |
| | | val = __queue.get(block=False) |
| | | if val: |
| | | print("read:", val) |
| | | |
| | | |
| | | def write(pipe): |
| | | while True: |
| | | __queue.put_nowait("123") |
| | | time.sleep(1) |
| | | break |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | p1, p2 = multiprocessing.Pipe() |
| | | t1 = threading.Thread(target=lambda: write(p1), daemon=True) |
| | | t1.start() |
| | | print("是否alive:", t1.is_alive()) |
| | | |
| | | threading.Thread(target=lambda: read(p2), daemon=True).start() |
| | | while True: |
| | | print("是否alive:", t1.is_alive()) |
| | | time.sleep(1) |
| | | input() |
| | | data = __queue.get() |
| | | print("数据:", data) |