[GRASS-SVN] r66540 - grass/trunk/lib/python/pygrass/rpc
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 19 15:13:30 PDT 2015
Author: huhabla
Date: 2015-10-19 15:13:30 -0700 (Mon, 19 Oct 2015)
New Revision: 66540
Modified:
grass/trunk/lib/python/pygrass/rpc/__init__.py
grass/trunk/lib/python/pygrass/rpc/base.py
Log:
pygrass rpc: Better error handling in rpc server
Modified: grass/trunk/lib/python/pygrass/rpc/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/rpc/__init__.py 2015-10-19 21:26:46 UTC (rev 66539)
+++ grass/trunk/lib/python/pygrass/rpc/__init__.py 2015-10-19 22:13:30 UTC (rev 66540)
@@ -198,11 +198,11 @@
def error_handler(data):
"""This function will be called in case of a fatal error in libgis"""
- #sys.stderr.write("Error handler was called\n")
+ # sys.stderr.write("Error handler was called\n")
# We send an exeption that will be handled in
# the parent process, then close the pipe
# and release any possible lock
- conn.send(FatalError())
+ conn.send(FatalError("G_fatal_error() was called in the server process"))
conn.close()
lock.release()
@@ -278,8 +278,20 @@
>>> len(ret)
12
+ >>> extent = {"north":100, "south":10, "east":30, "west":10,
+ ... "rows":2, "cols":2}
+ >>> ret = provider.get_raster_image_as_np(name=test_raster_name,
+ ... extent=extent)
+
>>> provider.stop()
+ >>> extent = {"rows":3, "cols":1}
+ >>> ret = provider.get_raster_image_as_np(name=test_raster_name,
+ ... extent=extent)
+ >>> len(ret)
+ 12
+
+
..
"""
self.check_server()
Modified: grass/trunk/lib/python/pygrass/rpc/base.py
===================================================================
--- grass/trunk/lib/python/pygrass/rpc/base.py 2015-10-19 21:26:46 UTC (rev 66539)
+++ grass/trunk/lib/python/pygrass/rpc/base.py 2015-10-19 22:13:30 UTC (rev 66540)
@@ -115,8 +115,8 @@
"""Check every 200 micro seconds if the server process is alive"""
while True:
time.sleep(0.2)
- #sys.stderr.write("Check server process\n")
- self._check_restart_server()
+ # sys.stderr.write("Check server process\n")
+ self._check_restart_server(caller="Server check thread")
self.threadLock.acquire()
if self.stopThread == True:
#sys.stderr.write("Stop thread\n")
@@ -137,7 +137,7 @@
def check_server(self):
self._check_restart_server()
- def _check_restart_server(self):
+ def _check_restart_server(self, caller="main thread"):
"""Restart the server if it was terminated
"""
self.threadLock.acquire()
@@ -148,22 +148,22 @@
self.server_conn.close()
self.start_server()
- logging.warning("Needed to restart the libgis server")
+ logging.warning("Needed to restart the libgis server, caller: %s"%(caller))
self.threadLock.release()
def safe_receive(self, message):
- """Receive the data and throw an FatalError exception in case the server
+ """Receive the data and throw a FatalError exception in case the server
process was killed and the pipe was closed by the checker thread"""
try:
ret = self.client_conn.recv()
if isinstance(ret, FatalError):
- raise FatalError()
+ raise ret
return ret
- except (EOFError, IOError, FatalError):
+ except (EOFError, IOError, FatalError), e:
# The pipe was closed by the checker thread because
# the server process was killed
- raise FatalError(message)
+ raise FatalError(message + "\n " + str(e))
def stop(self):
"""Stop the check thread, the libgis server and close the pipe
More information about the grass-commit
mailing list