Skip to content

Commit

Permalink
Fixes #180. Renamed _get_array_memmap to _get_array_mmap to better re…
Browse files Browse the repository at this point in the history
…flect that it now returns an mmap.mmap object and not a numpy memmap object. This still suits the purpose it was originally intended for.

git-svn-id: http://svn6.assembla.com/svn/pyfits/trunk@1801 ed100bfc-0583-0410-97f2-c26b58777a21
  • Loading branch information
embray committed Sep 6, 2012
1 parent ef08475 commit 35fdd4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
10 changes: 5 additions & 5 deletions lib/pyfits/hdu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyfits.util import (lazyproperty, _is_int, _is_pseudo_unsigned,
_unsigned_zero, _pad_length, itersubclasses,
encode_ascii, decode_ascii, BLOCK_SIZE, deprecated,
_get_array_memmap)
_get_array_mmap)
from pyfits.verify import _Verify, _ErrList


Expand Down Expand Up @@ -519,12 +519,12 @@ def _writeto(self, fileobj, inplace=False, copy=False):
# Of course, if we're copying the data to a new file we
# don't care about flushing the original mmap; instead just
# read it into the new file
memmap_array = None
array_mmap = None
else:
memmap_array = _get_array_memmap(self.data)
array_mmap = _get_array_mmap(self.data)

if memmap_array is not None:
memmap_array.flush()
if array_mmap is not None:
array_mmap.flush()
else:
self._file.seek(self._datLoc)
datloc, datsize = self._writedata(fileobj)
Expand Down
12 changes: 6 additions & 6 deletions lib/pyfits/hdu/hdulist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pyfits.hdu.table import _TableBaseHDU
from pyfits.util import (_is_int, _tmp_name, _pad_length, BLOCK_SIZE, isfile,
fileobj_name, fileobj_closed, fileobj_mode,
ignore_sigint, _get_array_memmap, indent)
ignore_sigint, _get_array_mmap, indent)
from pyfits.verify import _Verify, _ErrList, VerifyError, VerifyWarning


Expand Down Expand Up @@ -945,7 +945,7 @@ def _flush_resize(self):
if sys.platform.startswith('win'):
# Collect a list of open mmaps to the data; this well be used
# later. See below.
mmaps = [(idx, _get_array_memmap(hdu.data), hdu.data)
mmaps = [(idx, _get_array_mmap(hdu.data), hdu.data)
for idx, hdu in enumerate(self) if hdu._data_loaded]

hdulist.__file.close()
Expand All @@ -955,9 +955,9 @@ def _flush_resize(self):
# Close all open mmaps to the data. This is only necessary on
# Windows, which will not allow a file to be renamed or deleted
# until all handles to that file have been closed.
for idx, map, arr in mmaps:
if map is not None:
map.base.close()
for idx, mmap, arr in mmaps:
if mmap is not None:
mmap.close()

os.remove(self.__file.name)

Expand All @@ -978,7 +978,7 @@ def _flush_resize(self):
# Need to update the _file attribute and close any open mmaps
# on each HDU
if (hdu._data_loaded and
_get_array_memmap(hdu.data) is not None):
_get_array_mmap(hdu.data) is not None):
del hdu.data
hdu._file = ffo

Expand Down
13 changes: 6 additions & 7 deletions lib/pyfits/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import __builtin__
import functools
import itertools
import mmap
import os
import signal
import sys
Expand All @@ -24,8 +25,6 @@

import numpy as np

from numpy import memmap as Memmap


BLOCK_SIZE = 2880 # the FITS block size

Expand Down Expand Up @@ -734,18 +733,18 @@ def _tmp_name(input):
return fn


def _get_array_memmap(array):
def _get_array_mmap(array):
"""
If the array has a numpy.memmap as one of its bases, return the memmap
base; otherwise return None.
If the array has an mmap.mmap at base of its base chain, return the mmap
object; otherwise return None.
"""

if isinstance(array, Memmap):
if isinstance(array, mmap.mmap):
return array

base = array
while hasattr(base, 'base') and base.base is not None:
if isinstance(base.base, Memmap):
if isinstance(base.base, mmap.mmap):
return base.base
base = base.base

Expand Down

0 comments on commit 35fdd4a

Please sign in to comment.