Python mmap.ACCESS_COPY Examples
The following are 4
code examples of mmap.ACCESS_COPY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mmap
, or try the search function
.
Example #1
Source File: DataModel.py From dcc with Apache License 2.0 | 5 votes |
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)
Example #2
Source File: DataModel.py From qiew with GNU General Public License v2.0 | 5 votes |
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)
Example #3
Source File: DataModel.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #4
Source File: test_core.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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