Ejemplo n.º 1
0
    def _execute_request(self, msg_id, handler, params):
        """Executes request message handler."""
        method_name, method_type = get_help_attrs(handler)

        if asyncio.iscoroutinefunction(handler):
            future = asyncio.ensure_future(handler(params))
            self._client_request_futures[msg_id] = future
            future.add_done_callback(
                partial(self._execute_request_callback, method_name,
                        method_type, msg_id))
        else:
            # Can't be canceled
            if is_thread_function(handler):
                self._server.thread_pool.apply_async(
                    handler, (params, ),
                    callback=partial(
                        self._check_ret_type_and_send_response,
                        method_name,
                        method_type,
                        msg_id,
                    ),
                    error_callback=partial(self._execute_request_err_callback,
                                           msg_id))
            else:
                self._check_ret_type_and_send_response(method_name,
                                                       method_type, msg_id,
                                                       handler(params))
Ejemplo n.º 2
0
 def _execute_notification(self, handler, *params):
     """Executes notification message handler."""
     if asyncio.iscoroutinefunction(handler):
         future = asyncio.ensure_future(handler(*params))
         future.add_done_callback(self._execute_notification_callback)
     else:
         if is_thread_function(handler):
             self._server.thread_pool.apply_async(handler, (*params, ))
         else:
             handler(*params)