Exemplo n.º 1
0
 def _read_bytes(self, size, callback):
     try:
         self.stream.read_bytes(size, callback)
     except IOError:
         self.close()
         self.trigger(
             event.ERROR,
             conn=self,
             error=protocol.ConnectionClosedError('Stream is closed'),
         )
Exemplo n.º 2
0
 def _read_bytes(self, size, callback):
     try:
         fut = self.stream.read_bytes(size)
         IOLoop.current().add_future(fut, callback)
     except IOError:
         self.close()
         self.trigger(
             event.ERROR,
             conn=self,
             error=protocol.ConnectionClosedError('Stream is closed'),
         )
Exemplo n.º 3
0
    def _on_connection_close(self, conn, **kwargs):
        if conn.id in self.conns:
            del self.conns[conn.id]

        for callback in conn.callback_queue:
            try:
                callback(conn, protocol.ConnectionClosedError())
            except Exception:
                logger.exception('[%s] uncaught exception in callback', conn.id)

        logger.warning('[%s] connection closed', conn.id)
        logger.info('[%s] attempting to reconnect in %0.2fs', conn.id, self.reconnect_interval)
        reconnect_callback = functools.partial(self.connect_to_nsqd,
                                               host=conn.host, port=conn.port)
        self.io_loop.add_timeout(time.time() + self.reconnect_interval, reconnect_callback)