necst.web.process_manager

Local launcher process tracking for the NECST operator console.

This module only manages local subprocesses started by the console. It does not send telescope, recorder, or spectrometer commands.

make_launcher_log_paths(log_dir, stem)[source]

Return unique stdout/stderr log paths under log_dir.

Parameters:
  • log_dir (Path) –

  • stem (Any) –

Return type:

Tuple[Path, Path]

class ManagedProcessRecord(pid, category, label, action='', command=<factory>, stdout_path=None, stderr_path=None, started_at=<factory>, finished_at=None, returncode=None, status='running', final_logged=False, stop_requested_at=None, stop_reason='', _popen=None)[source]

Bases: object

A locally launched child process tracked by the operator console.

Parameters:
  • pid (int) –

  • category (str) –

  • label (str) –

  • action (str) –

  • command (List[str]) –

  • stdout_path (Optional[str]) –

  • stderr_path (Optional[str]) –

  • started_at (float) –

  • finished_at (Optional[float]) –

  • returncode (Optional[int]) –

  • status (str) –

  • final_logged (bool) –

  • stop_requested_at (Optional[float]) –

  • stop_reason (str) –

  • _popen (Optional[Popen[Any]]) –

pid: int
category: str
label: str
action: str = ''
command: List[str]
stdout_path: Optional[str] = None
stderr_path: Optional[str] = None
started_at: float
finished_at: Optional[float] = None
returncode: Optional[int] = None
status: str = 'running'
final_logged: bool = False
stop_requested_at: Optional[float] = None
stop_reason: str = ''
is_active()[source]

Return True while the local launcher is still considered active.

Older console code and status adaptation paths use this method instead of inspecting status directly. Keeping it on the record object makes status generation robust even when a process record has not just been converted through to_dict().

Return type:

bool

refresh()[source]

Poll the subprocess and return True if it finalized now.

Return type:

bool

request_stop(*, kill=False, reason='')[source]
Parameters:
  • kill (bool) –

  • reason (str) –

Return type:

None

wait(timeout)[source]
Parameters:

timeout (float) –

Return type:

bool

to_dict()[source]
Return type:

Dict[str, Any]

class ProcessRegistry[source]

Bases: object

Thread-safe registry of console-owned launcher subprocesses.

register_from_action_result(*, action, category, result_data, label)[source]
Parameters:
  • action (str) –

  • category (str) –

  • result_data (Mapping[str, Any]) –

  • label (str) –

Return type:

Optional[ManagedProcessRecord]

refresh()[source]
Return type:

List[ManagedProcessRecord]

all_records(*, refresh=True)[source]
Parameters:

refresh (bool) –

Return type:

List[ManagedProcessRecord]

active(*, category=None)[source]
Parameters:

category (Optional[str]) –

Return type:

List[ManagedProcessRecord]

counts()[source]
Return type:

Dict[str, Any]

request_stop(*, pid=None, category=None, kill=False, reason='')[source]
Parameters:
  • pid (Optional[int]) –

  • category (Optional[str]) –

  • kill (bool) –

  • reason (str) –

Return type:

List[ManagedProcessRecord]

graceful_shutdown(*, timeout_sec=3.0, kill_timeout_sec=1.0, reason='console shutdown')[source]
Parameters:
  • timeout_sec (float) –

  • kill_timeout_sec (float) –

  • reason (str) –

Return type:

Dict[str, Any]