[GRASS-SVN] r64819 - grass/trunk/lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 8 23:30:11 PDT 2015
Author: glynn
Date: 2015-03-08 23:30:11 -0700 (Sun, 08 Mar 2015)
New Revision: 64819
Modified:
grass/trunk/lib/python/script/array.py
Log:
Fix destruction (issue #2616)
Modified: grass/trunk/lib/python/script/array.py
===================================================================
--- grass/trunk/lib/python/script/array.py 2015-03-08 20:47:28 UTC (rev 64818)
+++ grass/trunk/lib/python/script/array.py 2015-03-09 06:30:11 UTC (rev 64819)
@@ -126,6 +126,15 @@
###############################################################################
+class _tempfile(object):
+ def __init__(self):
+ self.filename = grass.tempfile()
+
+ def __del__(self):
+ try_remove(self.filename)
+
+###############################################################################
+
class array(numpy.memmap):
def __new__(cls, dtype=numpy.double):
"""Define new numpy array
@@ -138,22 +147,19 @@
c = reg['cols']
shape = (r, c)
- filename = grass.tempfile()
+ tempfile = _tempfile()
self = numpy.memmap.__new__(
cls,
- filename=filename,
+ filename=tempfile.filename,
dtype=dtype,
mode='w+',
shape=shape)
- self.filename = filename
+ self.tempfile = tempfile
+ self.filename = tempfile.filename
return self
- def __del__(self):
- if isinstance(self, array):
- try_remove(self.filename)
-
def read(self, mapname, null=None):
"""Read raster map into array
@@ -259,23 +265,20 @@
d = reg['depths']
shape = (d, r, c)
- filename = grass.tempfile()
+ tempfile = _tempfile()
self = numpy.memmap.__new__(
cls,
- filename=filename,
+ filename=tempfile.filename,
dtype=dtype,
mode='w+',
shape=shape)
- self.filename = filename
+ self.tempfile = tempfile
+ self.filename = tempfile.filename
return self
- def __del__(self):
- if isinstance(self, array3d):
- try_remove(self.filename)
-
def read(self, mapname, null=None):
"""Read 3D raster map into array
More information about the grass-commit
mailing list