Hoist proc-title prefix to `_def_prefix` const
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[<reprol>]'` → `f'{prefix}[<reprol>]'`
i.e. `_subactor[<reprol>]` 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
(cherry picked from commit 3a45dbd503)
wkt/tooling_enhancements_from_mtf_spawner
parent
93558fe3c9
commit
fd8d39c0ce
|
|
@ -8,9 +8,9 @@ after `Actor` construction, so any spawned sub-actor process
|
|||
should:
|
||||
|
||||
- have `argv[0]` (== `/proc/<pid>/cmdline`) start with
|
||||
`tractor[<aid.reprol()>]`
|
||||
- have `/proc/<pid>/comm` start with `tractor[` (kernel
|
||||
truncates to ~15 bytes)
|
||||
`<_def_prefix>[<aid.reprol()>]` (currently `_subactor[…]`)
|
||||
- have `/proc/<pid>/comm` start with `<_def_prefix>[`
|
||||
(kernel truncates to ~15 bytes)
|
||||
- be detected as a tractor sub-actor by
|
||||
`_is_tractor_subactor(pid)` via the cmdline marker.
|
||||
|
||||
|
|
@ -27,7 +27,10 @@ import trio
|
|||
import tractor
|
||||
|
||||
from tractor.runtime._runtime import Actor
|
||||
from tractor.devx._proctitle import set_actor_proctitle
|
||||
from tractor.devx._proctitle import (
|
||||
set_actor_proctitle,
|
||||
_def_prefix,
|
||||
)
|
||||
from tractor._testing._reap import (
|
||||
_is_tractor_subactor,
|
||||
_read_cmdline,
|
||||
|
|
@ -41,8 +44,9 @@ _non_linux: bool = platform.system() != 'Linux'
|
|||
def test_set_actor_proctitle_format():
|
||||
'''
|
||||
`set_actor_proctitle()` returns the canonical
|
||||
`tractor[<aid.reprol()>]` form and actually mutates
|
||||
the running proc's title.
|
||||
`<_def_prefix>[<aid.reprol()>]` form (currently
|
||||
`_subactor[…]`) and actually mutates the running
|
||||
proc's title.
|
||||
|
||||
'''
|
||||
pytest.importorskip(
|
||||
|
|
@ -60,12 +64,14 @@ def test_set_actor_proctitle_format():
|
|||
)
|
||||
title: str = set_actor_proctitle(actor)
|
||||
|
||||
# canonical wrapping: `tractor[<aid.reprol()>]`. We
|
||||
# compare against the runtime-computed `reprol()`
|
||||
# rather than a hard-coded value so the test stays
|
||||
# decoupled from `Aid.reprol()`'s internal format
|
||||
# (currently `<name>@<pid>`, but could evolve).
|
||||
expected: str = f'tractor[{actor.aid.reprol()}]'
|
||||
# canonical wrapping: `<_def_prefix>[<aid.reprol()>]`.
|
||||
# We source BOTH the prefix (`_def_prefix`) and the
|
||||
# runtime-computed `reprol()` rather than hard-coding,
|
||||
# so the test stays decoupled from the prefix shape
|
||||
# (flipped to `_subactor` in `3a45dbd5`) AND from
|
||||
# `Aid.reprol()`'s internal format (currently
|
||||
# `<name>@<pid>`, but could evolve).
|
||||
expected: str = f'{_def_prefix}[{actor.aid.reprol()}]'
|
||||
assert title == expected
|
||||
# sanity: the actor's name must be in the title
|
||||
# somewhere (so a future `reprol()` change that
|
||||
|
|
@ -140,15 +146,17 @@ def test_subactor_proctitle_visible_via_proc():
|
|||
)
|
||||
|
||||
pid, info = matched[0]
|
||||
# canonical proctitle prefix in cmdline (full form)
|
||||
assert info['cmdline'].startswith('tractor[proctitle_boi@'), (
|
||||
f'cmdline missing `tractor[proctitle_boi@…]` prefix: '
|
||||
# canonical proctitle prefix in cmdline (full form);
|
||||
# prefix sourced from `_def_prefix` so it tracks the
|
||||
# `3a45dbd5` flip (`tractor[` -> `_subactor[`).
|
||||
assert info['cmdline'].startswith(f'{_def_prefix}[proctitle_boi@'), (
|
||||
f'cmdline missing `{_def_prefix}[proctitle_boi@…]` prefix: '
|
||||
f'{info["cmdline"]!r}'
|
||||
)
|
||||
# comm is kernel-truncated to ~15 bytes — just check the
|
||||
# `tractor[` prefix made it.
|
||||
assert info['comm'].startswith('tractor['), (
|
||||
f'comm missing `tractor[` prefix: {info["comm"]!r}'
|
||||
# `<_def_prefix>[` prefix made it.
|
||||
assert info['comm'].startswith(f'{_def_prefix}['), (
|
||||
f'comm missing `{_def_prefix}[` prefix: {info["comm"]!r}'
|
||||
)
|
||||
# intrinsic-signal detector should match.
|
||||
assert info['is_tractor'] is True
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -24,7 +24,10 @@ which" at a glance without needing to read full
|
|||
`/proc/<pid>/cmdline`.
|
||||
|
||||
Format:
|
||||
``tractor[<aid.reprol()>]`` e.g. ``tractor[doggy@1027301b]``
|
||||
``<_def_prefix>[<aid.reprol()>]`` e.g. ``_subactor[doggy@1027301b]``
|
||||
(prefix from the `_def_prefix` const, flipped `tractor` ->
|
||||
`_subactor` so sub-actor procs are visually distinct from the
|
||||
root in `ps`/`htop` and the reap-recognition markers.)
|
||||
|
||||
Uses the canonical `Aid.reprol()` form
|
||||
(``<name>@<uuid_short>``) so the proc-title matches the
|
||||
|
|
@ -52,7 +55,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 +78,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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue