import queue import mmap mapfile = '.malloc.mmap' with open(mapfile, 'wb') as f : f.write(b'\x00') q = queue.Queue() n = 0 with open(mapfile, 'r+b') as f : mm = mmap.mmap(f.fileno(), 0) while True : mm.seek(0) flag = mm.readline() if flag == b'\x01' : n += 1 q.put(n) mm[:] = b'\x00' else : if not q.empty() : print(q.get())
import os import mmap mapfile = '.malloc.mmap' if os.path.isfile(mapfile) : with open(mapfile, 'r+b') as f : mm = mmap.mmap(f.fileno(), 0) mm[:] = b'\x01'