summaryrefslogtreecommitdiff
path: root/numpy/core/memmap.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-06 21:06:12 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-06 21:06:12 +0000
commit48079cbd5da130e0d3db4e65814fe0d8f2cbd500 (patch)
treed09b1d3bcf90e6515041ee0290645c71b352afb9 /numpy/core/memmap.py
parentddff28c9595a3742e967f4eb892632d2ba99a0b6 (diff)
downloadnumpy-48079cbd5da130e0d3db4e65814fe0d8f2cbd500.tar.gz
A few cleanups to error code in PyArray_NewFromDescr. Some checks so that certain subclassees cannot be created inappropriately by .view()
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r--numpy/core/memmap.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index e9eb7241f..1ce068512 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -14,11 +14,13 @@ mode_equivalents = {
"write":"w+"
}
+_globalvar = 0
class memmap(ndarray):
def __new__(subtype, name, dtype=uint8, mode='r+', offset=0,
shape=None, fortran=0):
-
+ global _globalvar
+
try:
mode = mode_equivalents[mode]
except KeyError:
@@ -67,8 +69,10 @@ class memmap(ndarray):
mm = mmap.mmap(fid.fileno(), bytes, access=acc)
+ _globalvar = 1
self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
offset=offset, fortran=fortran)
+ _globalvar = 0
self._mmap = mm
self._offset = offset
self._mode = mode
@@ -77,10 +81,17 @@ class memmap(ndarray):
fid.close()
return self
+ def __array_finalize__(self, obj):
+ if not _globalvar:
+ raise ValueError, "Cannot create a memmap array that way"
+
def sync(self):
self._mmap.flush()
def __del__(self):
- self._mmap.flush()
- del self._mmap
+ try:
+ self._mmap.flush()
+ del self._mmap
+ except AttributeError:
+ pass