瀏覽代碼

Better exit handling of messenger and C-interface subprocesses

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58579 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 11 年之前
父節點
當前提交
c2f63f94b7

+ 5 - 3
lib/python/pygrass/messages/__init__.py

@@ -14,6 +14,7 @@ for details.
 @author Soeren Gebbert
 @author Soeren Gebbert
 """
 """
 
 
+import logging
 import sys
 import sys
 import grass.lib.gis as libgis
 import grass.lib.gis as libgis
 from multiprocessing import Process, Lock, Pipe
 from multiprocessing import Process, Lock, Pipe
@@ -28,8 +29,6 @@ class FatalError(Exception):
     def __str__(self):
     def __str__(self):
         return self.value
         return self.value
 
 
-
-
 def message_server(lock, conn):
 def message_server(lock, conn):
     """!The GRASS message server function designed to be a target for
     """!The GRASS message server function designed to be a target for
        multiprocessing.Process
        multiprocessing.Process
@@ -64,6 +63,8 @@ def message_server(lock, conn):
        - Debug: ["DEBUG", level, "MESSAGE"]
        - Debug: ["DEBUG", level, "MESSAGE"]
        - Percent: ["PERCENT", n, d, s]
        - Percent: ["PERCENT", n, d, s]
     """
     """
+    libgis.G_debug(1, "Start messenger server")
+    
     while True:
     while True:
         # Avoid busy waiting
         # Avoid busy waiting
         conn.poll(None)
         conn.poll(None)
@@ -77,7 +78,8 @@ def message_server(lock, conn):
         if message_type == "STOP":
         if message_type == "STOP":
             conn.close()
             conn.close()
             lock.release()
             lock.release()
-            return
+            libgis.G_debug(1, "Stop messenger server")
+            sys.exit()
 
 
         message = data[1]
         message = data[1]
 
 

+ 5 - 3
lib/python/temporal/c_libraries_interface.py

@@ -571,9 +571,10 @@ def _convert_timestamp_from_grass(ts):
 ###############################################################################
 ###############################################################################
 
 
 def _stop(lock, conn, data):
 def _stop(lock, conn, data):
-	conn.close()
-	lock.release()
-	sys.exit()
+    conn.close()
+    lock.release()
+    libgis.G_debug(1, "Stop C-interface server")
+    sys.exit()
 
 
 ###############################################################################
 ###############################################################################
 
 
@@ -595,6 +596,7 @@ def c_library_server(lock, conn):
     functions[RPCDefs.MAP_EXISTS] = _map_exists
     functions[RPCDefs.MAP_EXISTS] = _map_exists
 
 
     libgis.G_gisinit("c_library_server")
     libgis.G_gisinit("c_library_server")
+    libgis.G_debug(1, "Start C-interface server")
 
 
     while True:
     while True:
         # Avoid busy waiting
         # Avoid busy waiting

+ 16 - 0
lib/python/temporal/core.py

@@ -57,6 +57,8 @@ try:
 except:
 except:
     pass
     pass
 
 
+import atexit
+
 ###############################################################################
 ###############################################################################
 
 
 # Profiling function provided by the temporal framework
 # Profiling function provided by the temporal framework
@@ -315,6 +317,20 @@ def get_sql_template_path():
 
 
 ###############################################################################
 ###############################################################################
 
 
+def stop_subprocesses():
+    """!Stop the messenger and C-interface subprocesses
+    """
+    global message_interface
+    global c_library_interface
+    if message_interface:
+        message_interface.stop()
+    if c_library_interface:
+        c_library_interface.stop()
+
+atexit.register(stop_subprocesses)
+
+###############################################################################
+
 def init():
 def init():
     """!This function set the correct database backend from GRASS environmental variables
     """!This function set the correct database backend from GRASS environmental variables
        and creates the grass location database structure for raster,
        and creates the grass location database structure for raster,

+ 0 - 1
lib/python/temporal/register.py

@@ -61,7 +61,6 @@ def register_maps_in_space_time_dataset(
                        time and an increment is provided
                        time and an increment is provided
        @param fs Field separator used in input file
        @param fs Field separator used in input file
     """
     """
-
     start_time_in_file = False
     start_time_in_file = False
     end_time_in_file = False
     end_time_in_file = False
     msgr = get_tgis_message_interface()
     msgr = get_tgis_message_interface()

+ 1 - 1
lib/python/temporal/unittests_register.py

@@ -27,7 +27,7 @@ class TestRegisterFunctions(unittest.TestCase):
                                 w=0.0, t=1.0, b=0.0, res=10.0)
                                 w=0.0, t=1.0, b=0.0, res=10.0)
 
 
     def setUp(self):
     def setUp(self):
-        """!Create the test maps
+        """!Create the test maps and the space time raster datasets
         """
         """
         ret = 0
         ret = 0
         ret += grass.run_command("r.mapcalc", overwrite=True, quiet=True, 
         ret += grass.run_command("r.mapcalc", overwrite=True, quiet=True,