當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。