Administrator
2023-08-25 dbc2ec056e478704cc352586a22e9e07755b15f0
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
import mmap
import contextlib
import multiprocessing
import time
 
 
def run_process_1(pipe):
    with contextlib.closing(mmap.mmap(-1, 1000*100, tagname='l2-000333', access=mmap.ACCESS_WRITE)) as m:
        for i in range(1, 10001):
            m.seek(0)
            m.write(("msg " + str(i)).encode("utf-8"))
            m.flush()
            time.sleep(1)
 
 
def run_process_2(pipe):
    while True:
        with contextlib.closing(mmap.mmap(-1, 6, tagname='l2-000333', access=mmap.ACCESS_READ)) as m:
            s = m.read(1024)
            s = s.decode('utf-8').replace('\x00', '')
            if s:
                print(s)
            time.sleep(1)
 
 
if __name__ == '__main__':
    p1, p2 = multiprocessing.Pipe()
    serverProcess = multiprocessing.Process(target=run_process_1, args=(p1,))
    jueJinProcess = multiprocessing.Process(target=run_process_2, args=(p2,))
    serverProcess.start()
    jueJinProcess.start()
 
    while True:
        time.sleep(2)