本文整理匯總了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