def Start(self, idle_suicide_seconds=60, check_interval_seconds=60 * 10): # The temp options file is deleted by ycmd during startup with NamedTemporaryFile(mode='w+', delete=False) as options_file: json.dump(self._options_dict, options_file) options_file.flush() self._port = GetUnusedLocalhostPort() self._location = 'http://127.0.0.1:' + str(self._port) # Define environment variable to enable subprocesses coverage. See: # http://coverage.readthedocs.org/en/coverage-4.0.3/subprocess.html env = os.environ.copy() SetEnviron(env, 'COVERAGE_PROCESS_START', '.coveragerc') ycmd_args = [ sys.executable, PATH_TO_YCMD, '--port={0}'.format(self._port), '--options_file={0}'.format(options_file.name), '--log=debug', '--idle_suicide_seconds={0}'.format(idle_suicide_seconds), '--check_interval_seconds={0}'.format(check_interval_seconds), ] self._stdout = os.path.join(PathToCreatedTempDir(), 'test.log') with OpenForStdHandle(self._stdout) as stdout: _popen_handle = SafePopen(ycmd_args, stdin_windows=subprocess.PIPE, stdout=stdout, stderr=subprocess.STDOUT, env=env) self.server = psutil.Process(_popen_handle.pid)
def Start( self, idle_suicide_seconds = 60, check_interval_seconds = 60 * 10 ): # The temp options file is deleted by ycmd during startup with NamedTemporaryFile( mode = 'w+', delete = False ) as options_file: json.dump( self._options_dict, options_file ) options_file.flush() self._port = GetUnusedLocalhostPort() self._location = 'http://127.0.0.1:' + str( self._port ) # Define environment variable to enable subprocesses coverage. See: # http://coverage.readthedocs.org/en/coverage-4.0.3/subprocess.html env = os.environ.copy() SetEnviron( env, 'COVERAGE_PROCESS_START', '.coveragerc' ) ycmd_args = [ sys.executable, PATH_TO_YCMD, '--port={0}'.format( self._port ), '--options_file={0}'.format( options_file.name ), '--log=debug', '--idle_suicide_seconds={0}'.format( idle_suicide_seconds ), '--check_interval_seconds={0}'.format( check_interval_seconds ), ] stdout = CreateLogfile( LOGFILE_FORMAT.format( port = self._port, std = 'stdout' ) ) stderr = CreateLogfile( LOGFILE_FORMAT.format( port = self._port, std = 'stderr' ) ) self._logfiles.extend( [ stdout, stderr ] ) ycmd_args.append( '--stdout={0}'.format( stdout ) ) ycmd_args.append( '--stderr={0}'.format( stderr ) ) _popen_handle = SafePopen( ycmd_args, stdin_windows = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = env ) self._servers.append( psutil.Process( _popen_handle.pid ) ) self._WaitUntilReady() extra_conf = PathToTestFile( 'client', '.ycm_extra_conf.py' ) self.PostRequest( 'load_extra_conf_file', { 'filepath': extra_conf } )
def _StartServer(self): with self._server_state_lock: port = utils.GetUnusedLocalhostPort() self._hmac_secret = self._CreateHmacSecret() # racerd will delete the secret_file after it's done reading it with tempfile.NamedTemporaryFile(delete=False) as secret_file: secret_file.write(self._hmac_secret) args = [ self._racerd, 'serve', '--port', str(port), '-l', '--secret-file', secret_file.name ] # Enable logging of crashes env = os.environ.copy() SetEnviron(env, 'RUST_BACKTRACE', '1') if self._rust_source_path: args.extend(['--rust-src-path', self._rust_source_path]) filename_format = p.join(utils.PathToCreatedTempDir(), 'racerd_{port}_{std}.log') self._server_stdout = filename_format.format(port=port, std='stdout') self._server_stderr = filename_format.format(port=port, std='stderr') with utils.OpenForStdHandle(self._server_stderr) as fstderr: with utils.OpenForStdHandle(self._server_stdout) as fstdout: self._racerd_phandle = utils.SafePopen(args, stdout=fstdout, stderr=fstderr, env=env) self._racerd_host = 'http://127.0.0.1:{0}'.format(port) if not self.ServerIsRunning(): raise RuntimeError('Failed to start racerd!') _logger.info('Racerd started on: ' + self._racerd_host)