summaryrefslogtreecommitdiff
path: root/numpy/core/memmap.py
diff options
context:
space:
mode:
authorchris.burns <chris.burns@localhost>2008-03-08 00:42:40 +0000
committerchris.burns <chris.burns@localhost>2008-03-08 00:42:40 +0000
commit5a6dce26d43cfe96c978a88101bb0c70bca04775 (patch)
treea51847a8cb4b53b18194ddeaae962624c233713b /numpy/core/memmap.py
parent62e994938e1549b28117684efcff58d6c6adbc77 (diff)
downloadnumpy-5a6dce26d43cfe96c978a88101bb0c70bca04775.tar.gz
Refactor __del__ so views of memmaps do not close the python mmap.
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r--numpy/core/memmap.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 1c65bccee..3a53f9d16 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -199,9 +199,10 @@ class memmap(ndarray):
return self
def __array_finalize__(self, obj):
- self._mmap = None
if hasattr(obj, '_mmap'):
self._mmap = obj._mmap
+ else:
+ self._mmap = None
def flush(self):
"""Flush any changes in the array to the file on disk."""
@@ -217,9 +218,18 @@ class memmap(ndarray):
"""Close the memmap file. Only do this when deleting the object."""
if self.base is self._mmap:
self._mmap.close()
- elif self._mmap is not None:
- raise ValueError, "Cannot close a memmap that is being used " \
- "by another object."
+ self._mmap = None
+
+ # DEV NOTE: This error is raised on the deletion of each row
+ # in a view of this memmap. Python traps exceptions in
+ # __del__ and prints them to stderr. Suppressing this for now
+ # until memmap code is cleaned up and and better tested for
+ # numpy v1.1 Objects that do not have a python mmap instance
+ # as their base data array, should not do anything in the
+ # close anyway.
+ #elif self._mmap is not None:
+ #raise ValueError, "Cannot close a memmap that is being used " \
+ # "by another object."
def close(self):
"""Close the memmap file. Does nothing."""
@@ -227,8 +237,14 @@ class memmap(ndarray):
DeprecationWarning)
def __del__(self):
- self.flush()
- try:
- self._close()
- except ValueError:
- pass
+ if self._mmap is not None:
+ try:
+ # First run tell() to see whether file is open
+ self._mmap.tell()
+ except ValueError:
+ pass
+ else:
+ # flush any changes to disk, even if it's a view
+ self.flush()
+ self._close()
+