pythonpython-3.xmmap

Python mmap return Invalid argument


I tried to use mmap in Python

import mmap
import sys
f = open(sys.argv[1])
off = int(sys.argv[2])
mm = mmap.mmap(f.fileno(),length=0,access=mmap.ACCESS_READ,offset=off )

When off =0 that works fine .

But when off equal to any number (100 for example) I got OSError: [ERROR 22] Invalid argument


Solution

  • The offset must be a multiple of mmap.ALLOCATIONGRANULARITY but cannot be larger than the file size