Skip to content

Commit 8bcbe73

Browse files
committed
Enable debug_mode for subint_forkserver
The `subint_forkserver` backend's child runtime is trio-native (uses `_trio_main` + receives `SpawnSpec` over IPC just like `trio`/`subint`), so `tractor.devx.debug._tty_lock` works in those subactors. Wire the runtime gates that historically hard-coded `_spawn_method == 'trio'` to recognize this third backend. Deats, - new `_DEBUG_COMPATIBLE_BACKENDS` module-const in `tractor._root` listing the spawn backends whose subactor runtime is trio-native (`'trio'`, `'subint_forkserver'`). Both the enable-site (`_runtime_vars['_debug_mode'] = True`) and the cleanup-site reset key. off the same tuple — keep them in lockstep when adding backends - `open_root_actor`'s `RuntimeError` for unsupported backends now reports the full compatible-set + the rejected method instead of the stale "only `trio`" msg. - `runtime._runtime.Actor._from_parent`'s SpawnSpec-recv gate adds `'subint_forkserver'` to the existing `('trio', 'subint')` tuple — fork child-side runtime receives the same SpawnSpec IPC handshake as the others. - `subint_forkserver_proc` child-target now passes `spawn_method='subint_forkserver'` (was hard-coded `'trio'`) so `Actor.pformat()` / log lines reflect the actual parent-side spawn mechanism rather than masquerading as plain `trio`. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent 5e85f18 commit 8bcbe73

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

tractor/_root.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@
6969
logger = log.get_logger('tractor')
7070

7171

72+
# Spawn backends under which `debug_mode=True` is supported.
73+
# Requirement: the spawned subactor's root runtime must be
74+
# trio-native so `tractor.devx.debug._tty_lock` works. Matches
75+
# both the enable-site in `open_root_actor` and the cleanup-
76+
# site reset of `_runtime_vars['_debug_mode']` — keep them in
77+
# lockstep when adding backends.
78+
_DEBUG_COMPATIBLE_BACKENDS: tuple[str, ...] = (
79+
'trio',
80+
# forkserver children run `_trio_main` in their own OS
81+
# process — same child-side runtime shape as `trio_proc`.
82+
'subint_forkserver',
83+
)
84+
85+
7286
# TODO: stick this in a `@acm` defined in `devx.debug`?
7387
# -[ ] also maybe consider making this a `wrapt`-deco to
7488
# save an indent level?
@@ -293,10 +307,14 @@ async def open_root_actor(
293307
)
294308
loglevel: str = loglevel.upper()
295309

310+
# Debug-mode is currently only supported for backends whose
311+
# subactor root runtime is trio-native (so `tractor.devx.
312+
# debug._tty_lock` works). See `_DEBUG_COMPATIBLE_BACKENDS`
313+
# module-const for the list.
296314
if (
297315
debug_mode
298316
and
299-
_spawn._spawn_method == 'trio'
317+
_spawn._spawn_method in _DEBUG_COMPATIBLE_BACKENDS
300318
):
301319
_state._runtime_vars['_debug_mode'] = True
302320

@@ -318,7 +336,9 @@ async def open_root_actor(
318336

319337
elif debug_mode:
320338
raise RuntimeError(
321-
"Debug mode is only supported for the `trio` backend!"
339+
f'Debug mode currently supported only for '
340+
f'{_DEBUG_COMPATIBLE_BACKENDS!r} spawn backends, not '
341+
f'{_spawn._spawn_method!r}.'
322342
)
323343

324344
assert loglevel
@@ -619,7 +639,7 @@ async def ping_tpt_socket(
619639
if (
620640
debug_mode
621641
and
622-
_spawn._spawn_method == 'trio'
642+
_spawn._spawn_method in _DEBUG_COMPATIBLE_BACKENDS
623643
):
624644
_state._runtime_vars['_debug_mode'] = False
625645

tractor/runtime/_runtime.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,14 @@ async def _from_parent(
870870

871871
accept_addrs: list[UnwrappedAddress]|None = None
872872

873-
if self._spawn_method in ("trio", "subint"):
873+
if self._spawn_method in (
874+
'trio',
875+
'subint',
876+
# `subint_forkserver` parent-side sends a
877+
# `SpawnSpec` over IPC just like the other two
878+
# — fork child-side runtime is trio-native.
879+
'subint_forkserver',
880+
):
874881

875882
# Receive post-spawn runtime state from our parent.
876883
spawnspec: msgtypes.SpawnSpec = await chan.recv()

0 commit comments

Comments
 (0)