def override_global_exiter( cls, maybe_shutdown_socket: MaybeShutdownSocket, finalizer: Callable[[], None], ) -> Iterator[None]: with ExceptionSink.exiter_as(lambda previous_exiter: cls( maybe_shutdown_socket, finalizer, previous_exiter)): yield
def run_sync(self): """Synchronously run pantsd.""" os.environ.pop("PYTHONPATH") # Switch log output to the daemon's log stream from here forward. # Also, register an exiter using os._exit to ensure we only close stdio streams once. self._close_stdio() with self._pantsd_logging() as (log_stream, log_filename), ExceptionSink.exiter_as( lambda _: Exiter(exiter=os._exit)): # We don't have any stdio streams to log to anymore, so we log to a file. # We don't override the faulthandler destination because the stream we get will proxy things # via the rust logging code, and faulthandler needs to be writing directly to a real file # descriptor. When pantsd logging was originally initialised, we already set up faulthandler # to log to the correct file descriptor, so don't override it. # # We can get tracebacks of the pantsd process by tailing the pantsd log and sending it # SIGUSR2. ExceptionSink.reset_interactive_output_stream( log_stream, override_faulthandler_destination=False, ) # Reset the log location and the backtrace preference from the global bootstrap options. global_bootstrap_options = self._bootstrap_options.for_global_scope( ) ExceptionSink.reset_should_print_backtrace_to_terminal( global_bootstrap_options.print_exception_stacktrace) ExceptionSink.reset_log_location( global_bootstrap_options.pants_workdir) self._native.set_panic_handler() # Set the process name in ps output to 'pantsd' vs './pants compile src/etc:: -ldebug'. set_process_title(f"pantsd [{self._build_root}]") # Write service socket information to .pids. self._write_named_sockets(self._services.port_map) # Enter the main service runner loop. self._setup_services(self._services) self._run_services(self._services)
def wrap_global_exiter(cls, run_tracker, repro): with ExceptionSink.exiter_as(lambda previous_exiter: cls(run_tracker, repro, previous_exiter)): yield