git » pymisc » commit c2ba2ea

pickle_rpc: Handle server-side pickle/unpickle errors

author Alberto Bertogli
2008-12-13 20:48:42 UTC
committer Alberto Bertogli
2008-12-13 20:48:42 UTC
parent ba9729bd714e939747a3c5ee152b0be5417598c9

pickle_rpc: Handle server-side pickle/unpickle errors

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

pickle_rpc.py +9 -0
samples/pickle_rpc/c1.py +5 -0

diff --git a/pickle_rpc.py b/pickle_rpc.py
index 702f1e0..1709183 100644
--- a/pickle_rpc.py
+++ b/pickle_rpc.py
@@ -123,6 +123,11 @@ class Server (object):
 		except (socket.error, EOFError), info:
 			self.end_connection(fd)
 			return
+		except:
+			print 'Error unpickling'
+			traceback.print_exc()
+			self.end_connection(fd)
+			return
 
 		funcname = req[0]
 		params = req[1]
@@ -146,6 +151,10 @@ class Server (object):
 			pickle.dump(r, fd, -1)
 		except (socket.error, EOFError), info:
 			self.end_connection(fd)
+		except:
+			print 'Error pickling'
+			traceback.print_exc()
+			self.end_connection(fd)
 
 
 class UnknownFunction (Exception):
diff --git a/samples/pickle_rpc/c1.py b/samples/pickle_rpc/c1.py
index 8d471b2..b7dc821 100644
--- a/samples/pickle_rpc/c1.py
+++ b/samples/pickle_rpc/c1.py
@@ -10,3 +10,8 @@ try:
 except KeyError, info:
 	print 'successfuly caught', KeyError, info
 
+# the following causes an error unpickling on the server side, and it's useful
+# for testing that code path
+#class E(Exception): pass
+#cli.f(E)
+