Beispiel #1
0
    def _socket_connect(self, tracer):
        """
        Connects to the socket or raise a QdbFailedToConnect error.
        """
        log.info('Connecting to (%s, %d)' % tracer.address)

        for n in range(tracer.retry_attepts):
            # Try to connect to the server.
            try:
                self.socket = socket.create_connection(tracer.address)
                # If we made it here, we connected and no longer need to retry.
                break
            except socket.error:
                log.warn(
                    'Client %s failed to connect to (%s, %d) on attempt %d...'
                    % (tracer.uuid, tracer.address[0],
                       tracer.address[1], n + 1)
                )
        if self.socket is None:
            log.warn(
                'Failed to connect to (%s, %d), no longer retying.'
                % tracer.address
            )
            raise QdbFailedToConnect(
                tracer.address,
                tracer.retry_attepts
            )
        log.info('Client %s connected to (%s, %d)'
                 % (tracer.uuid, tracer.address[0],
                    tracer.address[1]))
Beispiel #2
0
    def start(self, auth_msg=''):
        """
        Begins processing commands from the server.
        """
        self.pipe, child_end = gipc.pipe()
        self._socket_connect()
        self.reader = gipc.start_process(
            target=ServerReader,
            args=(child_end, os.getpid(),
                  self.socket.fileno(),
                  self.tracer.pause_signal),
        )
        with Timeout(5, QdbFailedToConnect(self.tracer.address,
                                           self.tracer.retry_attepts),
                     green=self.green):
            # Receive a message to know that the reader is ready to begin.
            self.pipe.get()

        self.send(
            fmt_msg(
                'start', {
                    'uuid': self.tracer.uuid,
                    'auth': auth_msg,
                    'local': (0, 0),
                },
                serial=pickle.dumps,
            )
        )
        atexit.register(self.stop)
Beispiel #3
0
    def start(self, tracer, auth_msg=''):
        """
        Begins processing commands from the server.
        """
        self.pipe, child_end = self._pipe()
        self._socket_connect(tracer)
        self.reader = self._start_process(
            target=ServerReader,
            args=(child_end, os.getpid(),
                  self.socket.fileno(),
                  tracer.pause_signal),
        )
        with Timeout(5, QdbFailedToConnect(tracer.address,
                                           tracer.retry_attepts)):
            # Receive a message to know that the reader is ready to begin.
            while True:
                try:
                    self.pipe.get()
                    break
                except IOError as e:
                    # EAGAIN says to try the syscall again.
                    if e.errno != errno.EAGAIN:
                        raise

        self.send(
            fmt_msg(
                'start', {
                    'uuid': tracer.uuid,
                    'auth': auth_msg,
                    'local': (0, 0),
                },
                serial=json.dumps,
            )
        )
        signal.signal(
            tracer.pause_signal, partial(self._pause_handler, tracer)
        )
        atexit.register(self.stop)