Keep visualization worker alive until explicit stop
This commit is contained in:
parent
440ca7510f
commit
eb48ba1a51
12 changed files with 410 additions and 150 deletions
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import time
|
||||
from contextlib import suppress
|
||||
|
|
@ -40,18 +39,6 @@ def _read_request(control: socket.socket) -> dict[str, object]:
|
|||
return cast(dict[str, object], request)
|
||||
|
||||
|
||||
def _pid_exists(pid: int) -> bool:
|
||||
if pid <= 1:
|
||||
return False
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
except ProcessLookupError:
|
||||
return False
|
||||
except PermissionError:
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
arguments = _parser().parse_args(argv)
|
||||
control = socket.socket(fileno=arguments.control_fd)
|
||||
|
|
@ -61,10 +48,6 @@ def main(argv: list[str] | None = None) -> int:
|
|||
target = request["target"]
|
||||
snapshot = request["snapshot"]
|
||||
token = request["token"]
|
||||
initial_grace = request["initial_grace_seconds"]
|
||||
lease = request["lease_seconds"]
|
||||
monitor_interval = request["monitor_interval_seconds"]
|
||||
owner = request["owner_pid"]
|
||||
if not isinstance(target, dict) or not isinstance(snapshot, dict):
|
||||
raise ValueError("Visualization target is invalid")
|
||||
target = cast(dict[str, object], target)
|
||||
|
|
@ -76,13 +59,6 @@ def main(argv: list[str] | None = None) -> int:
|
|||
or (query is not None and not isinstance(query, str))
|
||||
or type(depth) is not int
|
||||
or not isinstance(token, str)
|
||||
or not isinstance(initial_grace, int | float)
|
||||
or isinstance(initial_grace, bool)
|
||||
or not isinstance(lease, int | float)
|
||||
or isinstance(lease, bool)
|
||||
or not isinstance(monitor_interval, int | float)
|
||||
or isinstance(monitor_interval, bool)
|
||||
or type(owner) is not int
|
||||
):
|
||||
raise ValueError("Visualization launch request is invalid")
|
||||
runner = VisualizationRunner(
|
||||
|
|
@ -90,9 +66,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||
snapshot_spec=cast(dict[str, object], snapshot),
|
||||
token=token,
|
||||
register_atexit=False,
|
||||
initial_grace_seconds=float(initial_grace),
|
||||
lease_seconds=float(lease),
|
||||
monitor_interval_seconds=float(monitor_interval),
|
||||
persistent=True,
|
||||
)
|
||||
visualization = runner.start(
|
||||
node_id=node_id,
|
||||
|
|
@ -107,7 +81,6 @@ def main(argv: list[str] | None = None) -> int:
|
|||
).encode("utf-8")
|
||||
+ b"\n"
|
||||
)
|
||||
owner_pid = owner
|
||||
except (DocForgeError, KeyError, OSError, TypeError, ValueError) as error:
|
||||
with suppress(OSError):
|
||||
control.sendall(
|
||||
|
|
@ -124,7 +97,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||
finally:
|
||||
control.close()
|
||||
|
||||
while runner.is_running() and _pid_exists(owner_pid):
|
||||
while runner.is_running():
|
||||
time.sleep(0.25)
|
||||
runner.stop()
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue