[GRASS-SVN] r64828 - grass/branches/releasebranch_7_0/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 10 07:19:18 PDT 2015


Author: annakrat
Date: 2015-03-10 07:19:18 -0700 (Tue, 10 Mar 2015)
New Revision: 64828

Modified:
   grass/branches/releasebranch_7_0/lib/python/script/array.py
Log:
Fix destruction (issue #2616), merge from trunk r64819

Modified: grass/branches/releasebranch_7_0/lib/python/script/array.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/array.py	2015-03-10 14:13:17 UTC (rev 64827)
+++ grass/branches/releasebranch_7_0/lib/python/script/array.py	2015-03-10 14:19:18 UTC (rev 64828)
@@ -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