本文整理汇总了Python中mmap.ACCESS_COPY属性的典型用法代码示例。如果您正苦于以下问题:Python mmap.ACCESS_COPY属性的具体用法?Python mmap.ACCESS_COPY怎么用?Python mmap.ACCESS_COPY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类mmap
的用法示例。
在下文中一共展示了mmap.ACCESS_COPY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_COPY [as 别名]
def __init__(self, filename):
self._filename = filename
self._f = open(filename, "rb")
# memory-map the file, size 0 means whole file
self._mapped = mmap.mmap(self._f.fileno(), 0, access=mmap.ACCESS_COPY)
super(FileDataModel, self).__init__(self._mapped)
示例2: test_mmap_allocate_error
# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import ACCESS_COPY [as 别名]
def test_mmap_allocate_error(self):
"""
Regression test for https://github.com/astropy/astropy/issues/1380
Temporarily patches mmap.mmap to raise an OSError if mode is ACCESS_COPY.
"""
mmap_original = mmap.mmap
# We patch mmap here to raise an error if access=mmap.ACCESS_COPY, which
# emulates an issue that an OSError is raised if the available address
# space is less than the size of the file even if memory mapping is used.
def mmap_patched(*args, **kwargs):
if kwargs.get('access') == mmap.ACCESS_COPY:
exc = OSError()
exc.errno = errno.ENOMEM
raise exc
else:
return mmap_original(*args, **kwargs)
with fits.open(self.data('test0.fits'), memmap=True) as hdulist:
with patch.object(mmap, 'mmap', side_effect=mmap_patched) as p:
with pytest.warns(AstropyUserWarning, match=r"Could not memory "
r"map array with mode='readonly'"):
data = hdulist[1].data
p.reset_mock()
assert not data.flags.writeable