Administrator
2023-08-25 d6da023297772c9df90c93c50a327786f5ae782d
test/test_mmap.py
@@ -5,21 +5,23 @@
def run_process_1(pipe):
    with contextlib.closing(mmap.mmap(-1, 1000*100, tagname='l2-000333', access=mmap.ACCESS_WRITE)) as m:
    with contextlib.closing(mmap.mmap(-1, 1000 * 100, tagname='l2-000333', access=mmap.ACCESS_WRITE)) as m:
        for i in range(1, 10001):
            start = time.time()
            m.seek(0)
            m.write(("msg " + str(i)).encode("utf-8"))
            m.write((f"msg {i} " * 10000).encode("utf-8"))
            m.flush()
            print("耗时", time.time() - start)
            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)
        with contextlib.closing(mmap.mmap(-1, 1000 * 100, tagname='l2-000333', access=mmap.ACCESS_READ)) as m:
            s = m.read(1000 * 100)
            s = s.decode('utf-8').replace('\x00', '')
            if s:
                print(s)
                print(len(s), s)
            time.sleep(1)