lib/ycmd/server.py
def start(self, ycmd_root_directory,
              ycmd_settings_path=None, working_directory=None,
              python_binary_path=None, server_idle_suicide_seconds=None,
              server_check_interval_seconds=None):
        '''
        Launches a ycmd server process with the given startup parameters. The
        only required startup parameter is `ycmd_root_directory`. If it is a
        `str`, then all other omitted parameters will be calculated with
        respect to it. If it is an instance of `StartupParameters`, then all
        other parameters will be ignored, as that class contains all the
        necessary information. It is preferable to use `StartupParameters`.

        If `ycmd_settings_path` is not provided, it is calculated relative to
        the `ycmd_root_directory` (the repository contains the template in
        `default_settings.json`).

        If `working_directory` is not provided, the current working directory
        is used, as calculated by the `os` module.

        If `python_binary_path` is not provided, the system-installed python is
        used. This implicitly depends on the `PATH` environment variable.

        If `server_idle_suicide_seconds` is not provided, a default is used.

        If `server_check_interval_seconds` is not provided, a default is used.

        It is preferable to use the concrete `StartupParameters` class, since
        this ends up constructing one anyway if it isn't already in that form.
        '''
        startup_parameters = to_startup_parameters(
            ycmd_root_directory,
            ycmd_settings_path=ycmd_settings_path,
            working_directory=working_directory,
            python_binary_path=python_binary_path,
            server_idle_suicide_seconds=server_idle_suicide_seconds,
            server_check_interval_seconds=server_check_interval_seconds,
        )
        assert isinstance(startup_parameters, StartupParameters), \
            '[internal] startup parameters is not StartupParameters: %r' % \
            (startup_parameters)

        # don't use instance logger, since it may not be initialized
        logger.debug(
            'preparing to start ycmd server with startup parameters: %s',
            startup_parameters,
        )
        self.set_status(Server.STARTING)

        # update parameters to reflect normalized settings:
        ycmd_root_directory = startup_parameters.ycmd_root_directory
        ycmd_settings_path = startup_parameters.ycmd_settings_path
        working_directory = startup_parameters.working_directory
        python_binary_path = startup_parameters.python_binary_path
        server_idle_suicide_seconds = \
            startup_parameters.server_idle_suicide_seconds
        server_check_interval_seconds = \
            startup_parameters.server_check_interval_seconds

        ycmd_server_hostname = '127.0.0.1'
        ycmd_server_port = get_unused_port(ycmd_server_hostname)
        ycmd_server_label = get_base_name(working_directory)

        # initialize connection parameters asap to set up the instance logger:
        with self._lock:
            self.hostname = ycmd_server_hostname
            self.port = ycmd_server_port

        try:
            ycmd_hmac_secret = new_hmac_secret(
                num_bytes=YCMD_HMAC_SECRET_LENGTH,
            )
            ycmd_settings_tempfile_path = write_ycmd_settings_file(
                ycmd_settings_path, ycmd_hmac_secret,
            )

            if ycmd_settings_tempfile_path is None:
                self._logger.error(
                    'failed to generate ycmd server settings file, '
                    'cannot start server'
                )
                raise RuntimeError(
                    'failed to generate ycmd server settings file'
                )

            # NOTE : This does not start the process.
            ycmd_process_handle = prepare_ycmd_process(
                startup_parameters, ycmd_settings_tempfile_path,
                ycmd_server_hostname, ycmd_server_port,
            )
        except Exception as e:
            self._logger.error(
                'failed to prepare ycmd server process: %r', e, exc_info=True,
            )
            self.set_status(Server.NULL)
            return

        self._logger.debug(
            'successfully prepared server process, about to start it'
        )

        with self._lock:
            self._process_handle = ycmd_process_handle
            self._stdout_log_handle = ycmd_process_handle.filehandles.stdout
            self._stderr_log_handle = ycmd_process_handle.filehandles.stderr

            self._startup_parameters = startup_parameters
            self._settings_tempfile_path = ycmd_settings_tempfile_path

            self.hostname = ycmd_server_hostname
            self.port = ycmd_server_port
            self.hmac = ycmd_hmac_secret
            self.label = ycmd_server_label

        def _check_and_remove_settings_tmp():
            try:
                if is_file(ycmd_settings_tempfile_path):
                    self._logger.debug(
                        'removing temporary settings file: %s',
                        ycmd_settings_tempfile_path,
                    )
                    os.remove(ycmd_settings_tempfile_path)
            except Exception as e:
                self._logger.warning(
                    'failed to remove temporary settings file: %r',
                    ycmd_settings_tempfile_path,
                )

        try:
            ycmd_process_handle.start()
        except ValueError as e:
            self._logger.error(
                'failed to launch ycmd server, argument error: %s', e,
            )
            _check_and_remove_settings_tmp()
        except OSError as e:
            self._logger.warning(
                'failed to launch ycmd server, system error: %s', e,
            )
            _check_and_remove_settings_tmp()

        if ycmd_process_handle.alive():
            self._logger.debug('process launched successfully!')
            self.set_status(Server.RUNNING)
        else:
            # nothing much we can do here - caller can check the output
            self._logger.debug(
                'process is no longer alive, there was probably an error'
            )
            self.set_status(Server.NULL)

        Launches a ycmd server process with the given startup parameters. The
        only required startup parameter is `ycmd_root_directory`. If it is a
        `str`, then all other omitted parameters will be calculated with
        respect to it. If it is an instance of `StartupParameters`, then all
        other parameters will be ignored, as that class contains all the
        necessary information. It is preferable to use `StartupParameters`.

        If `ycmd_settings_path` is not provided, it is calculated relative to
        the `ycmd_root_directory` (the repository contains the template in
        `default_settings.json`).

        If `working_directory` is not provided, the current working directory
        is used, as calculated by the `os` module.

        If `python_binary_path` is not provided, the system-installed python is
        used. This implicitly depends on the `PATH` environment variable.

        If `server_idle_suicide_seconds` is not provided, a default is used.

        If `server_check_interval_seconds` is not provided, a default is used.

        It is preferable to use the concrete `StartupParameters` class, since
        this ends up constructing one anyway if it isn't already in that form.
        
Launches a ycmd server process with the given startup parameters. The
only required startup parameter is `ycmd_root_directory`. If it is a
`str`, then all other omitted parameters will be calculated with
respect to it. If it is an instance of `StartupParameters`, then all
other parameters will be ignored, as that class contains all the
necessary information. It is preferable to use `StartupParameters`.



If `working_directory` is not provided, the current working directory
is used, as calculated by the `os` module.

If `python_binary_path` is not provided, the system-installed python is
used. This implicitly depends on the `PATH` environment variable.

If `server_idle_suicide_seconds` is not provided, a default is used.

If `server_check_interval_seconds` is not provided, a default is used.

It is preferable to use the concrete `StartupParameters` class, since
this ends up constructing one anyway if it isn't already in that form.
Launches a ycmd server process with the given startup parameters . The only required startup parameter is ` ycmd_root_directory ` . If it is a ` str ` then all other omitted parameters will be calculated with respect to it . If it is an instance of ` StartupParameters ` then all other parameters will be ignored as that class contains all the necessary information . It is preferable to use ` StartupParameters ` . If ` working_directory ` is not provided the current working directory is used as calculated by the ` os ` module . If ` python_binary_path ` is not provided the system - installed python is used . This implicitly depends on the ` PATH ` environment variable . If ` server_idle_suicide_seconds ` is not provided a default is used . If ` server_check_interval_seconds ` is not provided a default is used . It is preferable to use the concrete ` StartupParameters ` class since this ends up constructing one anyway if it isn ' t already in that form .
def start(self, ycmd_root_directory,
              ycmd_settings_path=None, working_directory=None,
              python_binary_path=None, server_idle_suicide_seconds=None,
              server_check_interval_seconds=None):
        startup_parameters = to_startup_parameters(
            ycmd_root_directory,
            ycmd_settings_path=ycmd_settings_path,
            working_directory=working_directory,
            python_binary_path=python_binary_path,
            server_idle_suicide_seconds=server_idle_suicide_seconds,
            server_check_interval_seconds=server_check_interval_seconds,
        )
        assert isinstance(startup_parameters, StartupParameters), \
            '[internal] startup parameters is not StartupParameters: %r' % \
            (startup_parameters)
        logger.debug(
            'preparing to start ycmd server with startup parameters: %s',
            startup_parameters,
        )
        self.set_status(Server.STARTING)
        ycmd_root_directory = startup_parameters.ycmd_root_directory
        ycmd_settings_path = startup_parameters.ycmd_settings_path
        working_directory = startup_parameters.working_directory
        python_binary_path = startup_parameters.python_binary_path
        server_idle_suicide_seconds = \
            startup_parameters.server_idle_suicide_seconds
        server_check_interval_seconds = \
            startup_parameters.server_check_interval_seconds
        ycmd_server_hostname = '127.0.0.1'
        ycmd_server_port = get_unused_port(ycmd_server_hostname)
        ycmd_server_label = get_base_name(working_directory)
        with self._lock:
            self.hostname = ycmd_server_hostname
            self.port = ycmd_server_port
        try:
            ycmd_hmac_secret = new_hmac_secret(
                num_bytes=YCMD_HMAC_SECRET_LENGTH,
            )
            ycmd_settings_tempfile_path = write_ycmd_settings_file(
                ycmd_settings_path, ycmd_hmac_secret,
            )
            if ycmd_settings_tempfile_path is None:
                self._logger.error(
                    'failed to generate ycmd server settings file, '
                    'cannot start server'
                )
                raise RuntimeError(
                    'failed to generate ycmd server settings file'
                )
            ycmd_process_handle = prepare_ycmd_process(
                startup_parameters, ycmd_settings_tempfile_path,
                ycmd_server_hostname, ycmd_server_port,
            )
        except Exception as e:
            self._logger.error(
                'failed to prepare ycmd server process: %r', e, exc_info=True,
            )
            self.set_status(Server.NULL)
            return
        self._logger.debug(
            'successfully prepared server process, about to start it'
        )
        with self._lock:
            self._process_handle = ycmd_process_handle
            self._stdout_log_handle = ycmd_process_handle.filehandles.stdout
            self._stderr_log_handle = ycmd_process_handle.filehandles.stderr
            self._startup_parameters = startup_parameters
            self._settings_tempfile_path = ycmd_settings_tempfile_path
            self.hostname = ycmd_server_hostname
            self.port = ycmd_server_port
            self.hmac = ycmd_hmac_secret
            self.label = ycmd_server_label
        def _check_and_remove_settings_tmp():
            try:
                if is_file(ycmd_settings_tempfile_path):
                    self._logger.debug(
                        'removing temporary settings file: %s',
                        ycmd_settings_tempfile_path,
                    )
                    os.remove(ycmd_settings_tempfile_path)
            except Exception as e:
                self._logger.warning(
                    'failed to remove temporary settings file: %r',
                    ycmd_settings_tempfile_path,
                )
        try:
            ycmd_process_handle.start()
        except ValueError as e:
            self._logger.error(
                'failed to launch ycmd server, argument error: %s', e,
            )
            _check_and_remove_settings_tmp()
        except OSError as e:
            self._logger.warning(
                'failed to launch ycmd server, system error: %s', e,
            )
            _check_and_remove_settings_tmp()
        if ycmd_process_handle.alive():
            self._logger.debug('process launched successfully!')
            self.set_status(Server.RUNNING)
        else:
            self._logger.debug(
                'process is no longer alive, there was probably an error'
            )
            self.set_status(Server.NULL)
def start ( self , ycmd_root_directory , ycmd_settings_path = None , working_directory = None , python_binary_path = None , server_idle_suicide_seconds = None , server_check_interval_seconds = None ) : startup_parameters = to_startup_parameters ( ycmd_root_directory , ycmd_settings_path = ycmd_settings_path , working_directory = working_directory , python_binary_path = python_binary_path , server_idle_suicide_seconds = server_idle_suicide_seconds , server_check_interval_seconds = server_check_interval_seconds , ) assert isinstance ( startup_parameters , StartupParameters ) , '[internal] startup parameters is not StartupParameters: %r' % ( startup_parameters ) logger . debug ( 'preparing to start ycmd server with startup parameters: %s' , startup_parameters , ) self . set_status ( Server . STARTING ) ycmd_root_directory = startup_parameters . ycmd_root_directory ycmd_settings_path = startup_parameters . ycmd_settings_path working_directory = startup_parameters . working_directory python_binary_path = startup_parameters . python_binary_path server_idle_suicide_seconds = startup_parameters . server_idle_suicide_seconds server_check_interval_seconds = startup_parameters . server_check_interval_seconds ycmd_server_hostname = '127.0.0.1' ycmd_server_port = get_unused_port ( ycmd_server_hostname ) ycmd_server_label = get_base_name ( working_directory ) with self . _lock : self . hostname = ycmd_server_hostname self . port = ycmd_server_port try : ycmd_hmac_secret = new_hmac_secret ( num_bytes = YCMD_HMAC_SECRET_LENGTH , ) ycmd_settings_tempfile_path = write_ycmd_settings_file ( ycmd_settings_path , ycmd_hmac_secret , ) if ycmd_settings_tempfile_path is None : self . _logger . error ( 'failed to generate ycmd server settings file, ' 'cannot start server' ) raise RuntimeError ( 'failed to generate ycmd server settings file' ) ycmd_process_handle = prepare_ycmd_process ( startup_parameters , ycmd_settings_tempfile_path , ycmd_server_hostname , ycmd_server_port , ) except Exception as e : self . _logger . error ( 'failed to prepare ycmd server process: %r' , e , exc_info = True , ) self . set_status ( Server . NULL ) return self . _logger . debug ( 'successfully prepared server process, about to start it' ) with self . _lock : self . _process_handle = ycmd_process_handle self . _stdout_log_handle = ycmd_process_handle . filehandles . stdout self . _stderr_log_handle = ycmd_process_handle . filehandles . stderr self . _startup_parameters = startup_parameters self . _settings_tempfile_path = ycmd_settings_tempfile_path self . hostname = ycmd_server_hostname self . port = ycmd_server_port self . hmac = ycmd_hmac_secret self . label = ycmd_server_label def _check_and_remove_settings_tmp ( ) : try : if is_file ( ycmd_settings_tempfile_path ) : self . _logger . debug ( 'removing temporary settings file: %s' , ycmd_settings_tempfile_path , ) os . remove ( ycmd_settings_tempfile_path ) except Exception as e : self . _logger . warning ( 'failed to remove temporary settings file: %r' , ycmd_settings_tempfile_path , ) try : ycmd_process_handle . start ( ) except ValueError as e : self . _logger . error ( 'failed to launch ycmd server, argument error: %s' , e , ) _check_and_remove_settings_tmp ( ) except OSError as e : self . _logger . warning ( 'failed to launch ycmd server, system error: %s' , e , ) _check_and_remove_settings_tmp ( ) if ycmd_process_handle . alive ( ) : self . _logger . debug ( 'process launched successfully!' ) self . set_status ( Server . RUNNING ) else : self . _logger . debug ( 'process is no longer alive, there was probably an error' ) self . set_status ( Server . NULL )
Launches a ycmd server process with the given startup parameters.
Launches a ycmd server process with the given startup parameters .
'''
        Launches a ycmd server process with the given startup parameters. The
        only required startup parameter is `ycmd_root_directory`. If it is a
        `str`, then all other omitted parameters will be calculated with
        respect to it. If it is an instance of `StartupParameters`, then all
        other parameters will be ignored, as that class contains all the
        necessary information. It is preferable to use `StartupParameters`.

        If `ycmd_settings_path` is not provided, it is calculated relative to
        the `ycmd_root_directory` (the repository contains the template in
        `default_settings.json`).

        If `working_directory` is not provided, the current working directory
        is used, as calculated by the `os` module.

        If `python_binary_path` is not provided, the system-installed python is
        used. This implicitly depends on the `PATH` environment variable.

        If `server_idle_suicide_seconds` is not provided, a default is used.

        If `server_check_interval_seconds` is not provided, a default is used.

        It is preferable to use the concrete `StartupParameters` class, since
        this ends up constructing one anyway if it isn't already in that form.
        ''' # don't use instance logger, since it may not be initialized # update parameters to reflect normalized settings: # initialize connection parameters asap to set up the instance logger: # NOTE : This does not start the process. # nothing much we can do here - caller can check the output
self
ycmd_root_directory
ycmd_settings_path
working_directory
python_binary_path
server_idle_suicide_seconds
server_check_interval_seconds