plesty.server.services.launch
Detached process launch: no zombies, and an exit code every process can read.
Several plesty-server processes look at the same servers and jobs — the
CLI, the agent, fleet run, the GUI. A child that its parent never reaps
is a zombie: kill(pid, 0) still succeeds, so a different process takes
it for alive and waits a full stop escalation for nothing. And a plain
detached child loses its exit code for everyone but its parent.
So nothing here is a direct child. launch() spawns a small waiter
(python -m plesty.server.services.launch) that detaches itself
(plesty.server.host.detach()), starts the real command with its output
appended to the log, forwards the interrupt it receives, waits, and writes
the exit code to exit_file. Callers track the waiter’s pid: alive means the
command runs; the exit file appears when it is over.
Functions
|
The file that asks the waiter of exit_file to stop its command. |
|
Start command detached; return the pid of the waiter that owns it. |
|
The exit code recorded in exit_file, or |
|
The waiter: run the command, forward the interrupt, record the exit code. |
|
|
|
|
|
Entry point of the waiter (spec as JSON on stdin). |
Module Contents
- plesty.server.services.launch.stop_file(exit_file: str | os.PathLike[str]) pathlib.Path
The file that asks the waiter of exit_file to stop its command.
Alongside the exit file, so anything that knows where a command reports its end also knows how to ask it to end (see
plesty.server.host.request_stop()).- Parameters:
exit_file (str | os.PathLike[str])
- Return type:
pathlib.Path
- plesty.server.services.launch.launch(command: collections.abc.Sequence[str], cwd: str | os.PathLike[str], env: collections.abc.Mapping[str, str], log: str | os.PathLike[str], exit_file: str | os.PathLike[str], banner: str = '') int
Start command detached; return the pid of the waiter that owns it.
- Parameters:
command (collections.abc.Sequence[str]) – The command line.
cwd (str | os.PathLike[str]) – Working directory.
env (collections.abc.Mapping[str, str]) – Full environment for the command.
log (str | os.PathLike[str]) – File its stdout+stderr are appended to.
exit_file (str | os.PathLike[str]) – File the exit code is written to when it ends (removed first, so its presence means “finished”).
banner (str) – A line written to the log before the command starts.
- Raises:
OSError – When the waiter itself cannot be started.
RuntimeError – When the waiter did not report a pid.
- Return type:
int
- plesty.server.services.launch.read_exit(exit_file: str | os.PathLike[str]) int | None
The exit code recorded in exit_file, or
Nonewhile it does not exist.- Parameters:
exit_file (str | os.PathLike[str])
- Return type:
int | None
- plesty.server.services.launch._wait(spec: dict[str, Any]) int
The waiter: run the command, forward the interrupt, record the exit code.
- Parameters:
spec (dict[str, Any])
- Return type:
int
- plesty.server.services.launch._write_exit(exit_file: str, code: int) None
- Parameters:
exit_file (str)
code (int)
- Return type:
None
- plesty.server.services.launch._report_pid(pid: int) None
- Parameters:
pid (int)
- Return type:
None
- plesty.server.services.launch.main() int
Entry point of the waiter (spec as JSON on stdin).
Reached as
python -m plesty.server.services.launchfrom a source checkout and asplesty-server _launchfrom a bundle.- Return type:
int