def start_client(self, addr):
        """Return ("socket", start_session) with a new client socket."""

        ptvsd.log.debug('Starting client daemon on {0!r}.', addr)

        addr = Address.from_raw(addr)
        self._singlesession = True
        with self.started():
            assert self.session is None
            client = create_client()
            connect(client, addr)
        sock = self._sock

        def start_session(**kwargs):
            self._check_ready_for_session()
            if self._server is not None:
                raise RuntimeError('running as server')
            if self._numsessions:
                raise RuntimeError('session stopped')

            try:
                self._bind_session(client)
                self._start_session_safely('ptvsd.Client', **kwargs)
                return self._session
            except Exception:
                self._stop_quietly()
                raise

        return sock, start_session
        def next_session(timeout=None, **kwargs):
            server = self._server
            sessionlock = self._sessionlock
            check_ready(checksession=False)

            ptvsd.log.debug('Getting next session...')
            sessionlock.acquire()  # Released in _finish_session().
            ptvsd.log.debug('Session lock acquired.')
            # It may have closed or stopped while we waited.
            check_ready()

            timeout = kwargs.pop('timeout', None)
            try:
                ptvsd.log.debug('Getting session socket...')
                client = connect(server, None, **kwargs)
                self._bind_session(client)
                ptvsd.log.debug('Starting session...')
                self._start_session_safely('ptvsd.Server', timeout=timeout)
                ptvsd.log.debug('Session started.')
                return self._session
            except Exception:
                ptvsd.log.exception(category=('D' if hidebadsessions else 'E'))
                with ignore_errors():
                    self._finish_session()
                if hidebadsessions:
                    ptvsd.log.debug('Hiding bad session')
                    return None
                self._stop_quietly()
                raise
Beispiel #3
0
        def next_session(timeout=None, **kwargs):
            server = self._server
            sessionlock = self._sessionlock
            check_ready(checksession=False)

            debug('getting next session')
            sessionlock.acquire()  # Released in _finish_session().
            debug('session lock acquired')
            # It may have closed or stopped while we waited.
            check_ready()

            timeout = kwargs.pop('timeout', None)
            try:
                debug('getting session socket')
                client = connect(server, None, **kwargs)
                self._bind_session(client)
                debug('starting session')
                self._start_session_safely('ptvsd.Server', timeout=timeout)
                debug('session started')
                return self._session
            except Exception as exc:
                debug('session exc:', exc, tb=True)
                with ignore_errors():
                    self._finish_session()
                if hidebadsessions:
                    debug('hiding bad session')
                    # TODO: Log the error?
                    return None
                self._stop_quietly()
                raise