当前位置: 首页>>代码示例>>Python>>正文


Python mmap.ACCESS_COPY属性代码示例

本文整理汇总了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) 
开发者ID:amimo,项目名称:dcc,代码行数:11,代码来源:DataModel.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:30,代码来源:test_core.py


注:本文中的mmap.ACCESS_COPY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。