import mmap fn = 'issue35686.bin' with open(fn, 'wb') as fd: fd.write(b'x' * 10000) with open(fn, 'rb') as fd: with mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ) as mm: with memoryview(mm) as data: data = data[1:] print("before memoryview cm exit") print("before mmap cm exit") print("before file cm exit")