Permalink
Browse files

Add 'error' method to the handle object. Call with sys.exc_info()

to forward a remote error to the calling side.
  • Loading branch information...
1 parent 9d746d0 commit c160869b9e18cc5b745a2f14147b50748e9567a0 @rjpower committed Jan 1, 2013
Showing with 8 additions and 4 deletions.
  1. +1 −1 setup.py
  2. +7 −3 src/rpc/server.py
View
@@ -4,7 +4,7 @@
setup(
name = "speedy",
description="Fast, non-blocking JSON based RPC system.",
- version = "0.19",
+ version = "0.20",
author="Russell Power",
author_email="power@cs.nyu.edu",
license="BSD",
View
@@ -6,6 +6,7 @@
import socket
import sys
import threading
+import types
import time
SERVER_RPCID_GEN = iter(xrange(100000000))
@@ -97,8 +98,10 @@ def rpc_finished(self, server_rpcid, *result):
# logging.info('RPCFINISHED %d', server_rpcid)
try:
handle = self._pending_rpcs[server_rpcid]
- logging.debug('Returning result for sid %d cid %d',
- handle.server_rpcid, handle.client_rpcid)
+ logging.debug('Returning result for sid %d cid %d', handle.server_rpcid, handle.client_rpcid)
+ if isinstance(result, tuple) and len(result) == 3 and isinstance(result[2], types.TracebackType):
+ result = RemoteException(result)
+
message = pickle((result, handle.elapsed(), None))
handle.connection.push_message(handle.client_rpcid, message)
del self._pending_rpcs[server_rpcid]
@@ -113,10 +116,11 @@ def _dispatch(self, handle):
handle.server_rpcid, handle.client_rpcid)
self._pending_rpcs[handle.server_rpcid] = handle
handle.done = lambda *args: self.rpc_finished(handle.server_rpcid, *args)
+ handle.error = lambda exc_info: self.rpc_finished(handle.server_rpcid, RemoteException(exc_info))
try:
getattr(self.handler, handle.method)(handle, *handle.args)
except:
logging.warn('Exception while handling method: %s', handle.method, exc_info=1)
- handle.done(RemoteException(sys.exc_info()))
+ handle.error(sys.exc_info())
# logging.debug('Dispatch finished.')

0 comments on commit c160869

Please sign in to comment.