| | |
| | | import multiprocessing |
| | | import queue |
| | | import threading |
| | | import time |
| | | |
| | |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_debug |
| | | |
| | | __queue = queue.Queue() |
| | | |
| | | |
| | | def read(pipe): |
| | | while True: |
| | | val = pipe.recv() |
| | | if val: |
| | | print("read:", val) |
| | | if not __queue.empty(): |
| | | val = __queue.get(block=False) |
| | | if val: |
| | | print("read:", val) |
| | | |
| | | |
| | | def write(pipe): |
| | | while True: |
| | | pipe.send("test") |
| | | __queue.put_nowait("123") |
| | | time.sleep(1) |
| | | break |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | p1, p2 = multiprocessing.Pipe() |
| | | threading.Thread(target=lambda: write(p1), daemon=True).start() |
| | | 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() |