From 3a45dbd5039aa4559ea38293952415332b795ac9 Mon Sep 17 00:00:00 2001 From: goodboy Date: Mon, 1 Jun 2026 20:26:22 -0400 Subject: [PATCH] Hoist proc-title prefix to `_def_prefix` const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the sub-actor proc-title prefix a single authoritative constant (`_proctitle._def_prefix`) so the reap-recognition markers and `xontrib` banner pick it up automatically — one place to flip the prefix shape going fwd. Deats, - `_proctitle._def_prefix: str = '_subactor'`. New module-level const consumed by everything that needs to know the prefix. - `set_actor_proctitle(actor, prefix=_def_prefix)`: takes an explicit `prefix` arg (default = the const) so callers can override per-spawn if they want. - Default proc-title format: `'tractor[]'` → `f'{prefix}[]'` i.e. `_subactor[]` by default. - `_testing/_reap.py`: cmdline + comm markers source the prefix from `_proctitle._def_prefix` instead of the hardcoded `'tractor['`. So `_is_tractor_subactor()` tracks the const automatically. - `xontrib/tractor_diag.xsh`: `acli.reap` orphan-mode banner now interpolates the `_TRACTOR_PROC_CMDLINE_MARKERS` tuple directly so the human-readable mode line stays in sync if the prefix shape changes again. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tractor/_testing/_reap.py | 8 +++++--- tractor/devx/_proctitle.py | 10 ++++++++-- xontrib/tractor_diag.xsh | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tractor/_testing/_reap.py b/tractor/_testing/_reap.py index 96ce3c70..fa4df944 100644 --- a/tractor/_testing/_reap.py +++ b/tractor/_testing/_reap.py @@ -90,7 +90,6 @@ keys are caller-defined). ''' from __future__ import annotations - import os import pathlib import re @@ -99,6 +98,9 @@ import stat import sys import time + +from tractor.devx import _proctitle + # `/dev/shm` is the POSIX-shm filesystem on Linux + FreeBSD. # macOS uses `shm_open` syscalls without a fs-visible path, # so the shm helpers refuse to run there. @@ -230,9 +232,9 @@ def _read_comm(pid: int) -> str: # while `cmdline` for zombies often reads as empty. _TRACTOR_PROC_CMDLINE_MARKERS: tuple[str, ...] = ( 'tractor._child', - 'tractor[', + _proctitle._def_prefix, ) -_TRACTOR_PROC_COMM_MARKER: str = 'tractor[' +_TRACTOR_PROC_COMM_MARKER: str = _proctitle._def_prefix def _is_tractor_subactor(pid: int) -> bool: diff --git a/tractor/devx/_proctitle.py b/tractor/devx/_proctitle.py index d52f860e..175c5f5f 100644 --- a/tractor/devx/_proctitle.py +++ b/tractor/devx/_proctitle.py @@ -52,7 +52,13 @@ except ImportError: _stp = None -def set_actor_proctitle(actor: 'Actor') -> str | None: +_def_prefix: str = '_subactor' + + +def set_actor_proctitle( + actor: 'Actor', + prefix: str = _def_prefix, +) -> str | None: ''' Set the calling process's proc-title to identify it as a tractor sub-actor. @@ -69,6 +75,6 @@ def set_actor_proctitle(actor: 'Actor') -> str | None: if _stp is None: return None - title: str = f'tractor[{actor.aid.reprol()}]' + title: str = f'{prefix}[{actor.aid.reprol()}]' _stp.setproctitle(title) return title diff --git a/xontrib/tractor_diag.xsh b/xontrib/tractor_diag.xsh index 987fd0b4..37f97a7c 100644 --- a/xontrib/tractor_diag.xsh +++ b/xontrib/tractor_diag.xsh @@ -488,6 +488,7 @@ def _tractor_reap(args): reap, reap_shm, reap_uds, + _TRACTOR_PROC_CMDLINE_MARKERS, ) rc: int = 0 @@ -500,9 +501,8 @@ def _tractor_reap(args): else: pids = find_orphans() mode = ( - 'orphans (PPid==1, intrinsic ' - 'cmdline/comm match — `tractor[…]` or ' - '`tractor._child`)' + f'orphans (PPid==1, intrinsic ' + f'cmdline/comm match — {_TRACTOR_PROC_CMDLINE_MARKERS}' ) if not pids: