def __handle_input(self, msg): payload = comm.unpack(msg.body) logging.debug("At %d I got: telling me [%s]." % (time.time(), payload)) try: # # JSON-RPC invocations are send as a dict, multiple invocations # can be requested by sending a list of dicts. # To simplify code then the handling of JSON-RPC-BATCH is implemented # and the JSON-RPC-SINGLE is converted to JSON-RPC-BATCH with just one # element in the list. # if isinstance(payload, dict): # Single RPC invocation invocations = [ payload ] elif isinstance(payload, list): # Multiple RPC invocations invocations = payload else: # Unsupported payload # # NOTE: The type-checks above is not sufficient to validate whether # the request is actually a valid JSON-RPC invocation. # # It is up to the RPC method itself to validate the input and # to determine whether it has received the right amount of args! # logging.debug("Supported payload-type.") for invocation in invocations: # Queue each method if invocation["method"] in self.internal_rpc: # Invoke RPC self.output_queue.put((None, invocation, self.invoke_rpc(invocation))) else: # Enqueue RPC self.workers[None][invocation['method']].input_queue.put(invocation) except: logging.debug('Error invoking RPC.', exc_info=3)
def recv_cb(msg): payload = comm.unpack(msg) pprint.pprint(payload)