进程1的程序代码:
import mmap
import time
# write a simple example file
#with open("hello.txt", "wb") as f:
# f.write(b"Hello Python!n")
with open("hello.txt", "r+b") as f:
# memory-map the file, size 0 means whole file
mm = mmap.mmap(f.fileno(), 0)
# read content via standard file methods
print(mm.readline()) # prints b"Hello Python!n"
# read content via slice notation
print(mm[:5]) # prints b"Hello"
# update content using slice notation;
# note that new content must have same size
mm[6:] = b" ktest!n"
time.sleep(60)
# ... and read again using standard file methods
mm.seek(0)
print(mm.readline()) # prints b"Hello world!n"
# close the map
mm.close()
负责对内存写,充当生产者的身份。
进程2的程序代码:
import mmap
import time
# write a simple example file
# with open("hello.txt"


