Administrator
2023-08-31 d47fbd65ab8197348ad293b7948fcdd2f8995594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import multiprocessing
import queue
import threading
import time
 
from huaxin_client import l2_data_manager
from log_module import async_log_util
from log_module.log import logger_debug
 
__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()