Exemplo n.º 1
0
 def recv_loop(self):
     # Called from tornado
     url = "ws://%s:%d/ws" % (self.hostname, self.port)
     self._conn = yield websocket_connect(
         url, connect_timeout=self.connect_timeout - 0.5)
     cothread.Callback(self._connected_queue.put, None)
     while True:
         message = yield self._conn.read_message()
         if message is None:
             self._conn = None
             cothread.Callback(self._report_fault)
             return
         self.on_message(message)
Exemplo n.º 2
0
 def update_request_received(self, part, info):
     # type: (Part, builtin.infos.RequestInfo) -> None
     if info.mri == ".":
         # This is for us
         controller = self
     else:
         controller = self.process.get_controller(info.mri)
     cothread.Callback(controller.handle_request, info.request)
Exemplo n.º 3
0
 def handle_response(response):
     # Called from tornado
     if not isinstance(response, Delta):
         # Return or Error is the end of our subscription, log and ignore
         self.log.debug("Proxy got response %r", response)
         done_queue.put(None)
     else:
         cothread.Callback(self._handle_response, response, block,
                           done_queue)
Exemplo n.º 4
0
    def on_message(self, message):
        """Pass response from server to process receive queue

        Args:
            message(str): Received message
        """
        # Called in tornado loop
        try:
            self.log.debug("Got message %s", message)
            d = json_decode(message)
            response = deserialize_object(d, Response)
            if isinstance(response, (Return, Error)):
                request = self._request_lookup.pop(response.id)
                if isinstance(response, Error):
                    # Make the message an exception so it can be raised
                    response.message = ResponseError(response.message)
            else:
                request = self._request_lookup[response.id]
            # Transfer the work of the callback to cothread
            cothread.Callback(request.callback, response)
        except Exception:
            # If we don't catch the exception here, tornado will spew odd
            # error messages about 'HTTPRequest' object has no attribute 'path'
            self.log.exception("on_message(%r) failed", message)
Exemplo n.º 5
0
 def _update_remote_blocks(self, response):
     response = deserialize_object(response, Update)
     cothread.Callback(self.remote_blocks.set_value, response.value)