[GRASS-SVN] r58597 - grass/trunk/gui/wxpython/timeline

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 3 13:02:40 PST 2014


Author: huhabla
Date: 2014-01-03 13:02:39 -0800 (Fri, 03 Jan 2014)
New Revision: 58597

Modified:
   grass/trunk/gui/wxpython/timeline/frame.py
Log:
Implemented explicit kill in the destructor of g.gui.timeline.
The tgis messenger and C-interface subprocesses are terminated as well
to avoid orphaned processes.
A SLQ connection object is now created in the constructor to reduce the 
number of expensive database connection openings and closing while data preparation. 


Modified: grass/trunk/gui/wxpython/timeline/frame.py
===================================================================
--- grass/trunk/gui/wxpython/timeline/frame.py	2014-01-03 18:40:28 UTC (rev 58596)
+++ grass/trunk/gui/wxpython/timeline/frame.py	2014-01-03 21:02:39 UTC (rev 58597)
@@ -18,6 +18,7 @@
 import os
 import sys
 import wx
+import signal
 from math import ceil
 from itertools import cycle
 import numpy as np
@@ -73,12 +74,33 @@
         wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=_("Timeline Tool"))
 
         tgis.init()
+        self.is_standalone = False
+        # Check if a parent exists. The module g.gui.timeline runs in stand alone mode
+        # in case there is no parent. 
+        if parent is None:
+            self.is_standalone = True
         self.datasets = []
         self.timeData = {}
         self._layout()
         self.temporalType = None
         self.unit = None
+        # We create a database interface here to speedup the GUI
+        self.dbif = tgis.SQLDatabaseInterfaceConnection()
+        self.dbif.connect()
 
+    def __del__(self):
+        """!Close the database interface and stop the messenger and C-interface
+           subprocesses.
+        """
+        if self.dbif.connected is True:
+            self.dbif.close()
+        tgis.stop_subprocesses()
+        # We need to kill the child process explicitely to avoid 
+        # orphaned g.gui.timeline stand-alone processes. 
+        if self.is_standalone is True:
+            pid = os.getpid()
+            os.kill(pid, signal.SIGQUIT) #or signal.SIGKILL 
+        
     def _layout(self):
         """!Creates the main panel with all the controls on it:
              * mpl canvas
@@ -145,15 +167,16 @@
         self.timeData = {}
         mode = None
         unit = None
+
         for series in timeseries:
             name = series[0] + '@' + series[1]
             etype = series[2]
             sp = tgis.dataset_factory(etype, name)
-            if not sp.is_in_db():
+            if not sp.is_in_db(dbif=self.dbif):
                 GError(self, message=_("Dataset <%s> not found in temporal database") % (name))
                 return
 
-            sp.select()
+            sp.select(dbif=self.dbif)
 
             self.timeData[name] = {}
             self.timeData[name]['elementType'] = series[2]
@@ -167,8 +190,8 @@
                 return
 
             # check topology
-            maps = sp.get_registered_maps_as_objects()
-            self.timeData[name]['validTopology'] = sp.check_temporal_topology(maps)
+            maps = sp.get_registered_maps_as_objects(dbif=self.dbif)
+            self.timeData[name]['validTopology'] = sp.check_temporal_topology(maps=maps, dbif=self.dbif)
 
             self.timeData[name]['temporalMapType'] = sp.get_map_time()  # point/interval
             self.timeData[name]['unit'] = None  # only with relative
@@ -194,7 +217,7 @@
                                 'north', 'south', 'west', 'east'])
 
             rows = sp.get_registered_maps(columns=columns, where=None,
-                                          order='start_time', dbif=None)
+                                          order='start_time', dbif=self.dbif)
             if rows is None:
                 rows = []
             for row in rows:
@@ -385,7 +408,7 @@
         @return (mapName, mapset, type)
         """
         validated = []
-        tDict = tgis.tlist_grouped('stds', group_type=True)
+        tDict = tgis.tlist_grouped('stds', group_type=True, dbif=self.dbif)
         # nested list with '(map, mapset, etype)' items
         allDatasets = [[[(map, mapset, etype) for map in maps]
                      for etype, maps in etypesDict.iteritems()]



More information about the grass-commit mailing list