Exemple #1
0
 def __call__(
     self,
     command: str,
     args: Tuple[str, ...],
     env: Dict[str, str],
     working_directory: bytes,
     cancellation_latch: PySessionCancellationLatch,
     stdin_fd: int,
     stdout_fd: int,
     stderr_fd: int,
 ) -> ExitCode:
     request_timeout = float(env.get("PANTSD_REQUEST_TIMEOUT_LIMIT", -1))
     # NB: Order matters: we acquire a lock before mutating either `sys.std*`, `os.environ`, etc.
     with self._one_run_at_a_time(
             stderr_fd,
             cancellation_latch=cancellation_latch,
             timeout=request_timeout,
     ), stdio_as(stdin_fd=stdin_fd,
                 stdout_fd=stdout_fd,
                 stderr_fd=stderr_fd), hermetic_environment_as(
                     **env), argv_as((command, ) + args):
         # NB: Run implements exception handling, so only the most primitive errors will escape
         # this function, where they will be logged to the pantsd.log by the server.
         logger.info(f"handling request: `{' '.join(args)}`")
         try:
             return self.single_daemonized_run(working_directory.decode(),
                                               cancellation_latch)
         finally:
             logger.info(f"request completed: `{' '.join(args)}`")
Exemple #2
0
    def run_sync(self):
        """Synchronously run pantsd."""
        os.environ.pop("PYTHONPATH")

        global_bootstrap_options = self._bootstrap_options.for_global_scope()
        # Set the process name in ps output to 'pantsd' vs './pants compile src/etc:: -ldebug'.
        set_process_title(f"pantsd [{self._build_root}]")

        # Switch log output to the daemon's log stream, and empty `env` and `argv` to encourage all
        # further usage of those variables to happen via engine APIs and options.
        self._close_stdio()
        with initialize_stdio(global_bootstrap_options), argv_as(
                tuple()), hermetic_environment_as():
            # Install signal and panic handling.
            ExceptionSink.install(
                log_location=init_workdir(global_bootstrap_options),
                pantsd_instance=True)
            native_engine.maybe_set_panic_handler()

            self._initialize_metadata()

            # Check periodically whether the core is valid, and exit if it is not.
            while self._core.is_valid():
                time.sleep(self.JOIN_TIMEOUT_SECONDS)

            # We're exiting: join the server to avoid interrupting ongoing runs.
            self._logger.info(
                "Waiting for ongoing runs to complete before exiting...")
            native_engine.nailgun_server_await_shutdown(self._server)
            self._logger.info("Exiting pantsd")