给定mmap的构造函数声明:
class mmap.mmap(fileno,length [,flags [,prot [,access [,offset]]]])
如何指定访问权限和偏移?
文件说明:
access may be specified in lieu of flags and prot as an optional
keyword parameter. It is an error to specify both flags, prot and
access. See the description of access above for information on how to
use this parameter.
所以我试着去做
> mmap.mmap(file_no,length,offset,access = mmap.ACCESS_COPY)
> mmap.mmap(file_no,length,access = mmap.ACCESS_COPY,offset = offset)
m = mmap.mmap(f.fileno(), 4, access=mmap.ACCESS_COPY, offset=2)
Traceback (most recent call last):
File “”, line 1, in
mmap.error: [Errno 22] Invalid argument
> mmap.mmap(file_no,length,mmap.ACCESS_COPY,offset)
但我无法让它发挥作用.为什么这让我这么困惑?
解决方法:
此错误与访问无关.如documented,偏移量必须是mmap.PAGESIZE或mmap.ALLOCATIONGRANULARITY的倍数.