Add `use_stackscope` runtime var for subactor init
Track `stackscope` enablement in `RuntimeVars` so the flag propagates to subactors via the standard rtvar IPC path instead of relying solely on the `TRACTOR_ENABLE_STACKSCOPE` env var. Deats, - add `use_stackscope: bool` to `RuntimeVars` struct + defaults dict - `enable_stack_on_sig()` sets the rtvar on successful `stackscope` import, asserts unset on `ImportError` - nest stackscope init under `_debug_mode` gate in `Actor.async_main`, check rtvar alongside env var - defer `maybe_init_greenback` import to its own `use_greenback` branch (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codesubint_forkserver_backend
parent
e2b790a70d
commit
48523358cf
|
|
@ -381,11 +381,13 @@ def enable_stack_on_sig(
|
|||
message=r"coroutine method '(asend|athrow)' .* was never awaited",
|
||||
)
|
||||
import stackscope
|
||||
_state._runtime_vars['use_stackscope'] = True
|
||||
except ImportError:
|
||||
log.warning(
|
||||
'The `stackscope` lib is not installed!\n'
|
||||
'`Ignoring enable_stack_on_sig() call!\n'
|
||||
)
|
||||
assert not _state._runtime_vars['use_stackscope']
|
||||
return None
|
||||
|
||||
# Capture the trio token if we're inside `trio.run`
|
||||
|
|
|
|||
|
|
@ -940,32 +940,30 @@ class Actor:
|
|||
# `tractor._testing.pytest`'s `--enable-stackscope`
|
||||
# CLI flag — env var propagates via fork-inherited
|
||||
# environ).
|
||||
import os
|
||||
if (
|
||||
rvs['_debug_mode']
|
||||
or
|
||||
os.environ.get('TRACTOR_ENABLE_STACKSCOPE')
|
||||
):
|
||||
from ..devx import (
|
||||
enable_stack_on_sig,
|
||||
maybe_init_greenback,
|
||||
)
|
||||
try:
|
||||
# TODO: maybe return some status msgs upward
|
||||
# to that we can emit them in `con_status`
|
||||
# instead?
|
||||
log.devx(
|
||||
'Enabling `stackscope` traces on SIGUSR1'
|
||||
)
|
||||
enable_stack_on_sig()
|
||||
if rvs['_debug_mode']:
|
||||
if (
|
||||
rvs.get('use_stackscope')
|
||||
or
|
||||
os.environ.get('TRACTOR_ENABLE_STACKSCOPE')
|
||||
):
|
||||
from ..devx import enable_stack_on_sig
|
||||
try:
|
||||
# TODO: maybe return some status msgs upward
|
||||
# to that we can emit them in `con_status`
|
||||
# instead?
|
||||
log.devx(
|
||||
'Enabling `stackscope` traces on SIGUSR1'
|
||||
)
|
||||
enable_stack_on_sig()
|
||||
|
||||
except ImportError:
|
||||
log.warning(
|
||||
'`stackscope` not installed for use in '
|
||||
'debug mode / `--enable-stackscope`!'
|
||||
)
|
||||
except ImportError:
|
||||
log.warning(
|
||||
'`stackscope` not installed for use in '
|
||||
'debug mode / `--enable-stackscope`!'
|
||||
)
|
||||
|
||||
if rvs.get('use_greenback', False):
|
||||
from ..devx import maybe_init_greenback
|
||||
maybe_mod: ModuleType|None = await maybe_init_greenback()
|
||||
if maybe_mod:
|
||||
log.devx(
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ class RuntimeVars(Struct):
|
|||
repl_fixture: bool|Callable = False # |AbstractContextManager[bool]
|
||||
# for `tractor.pause_from_sync()` & `breakpoint()` support
|
||||
use_greenback: bool = False
|
||||
use_stackscope: bool = False
|
||||
|
||||
# infected-`asyncio`-mode: `trio` running as guest.
|
||||
_is_infected_aio: bool = False
|
||||
|
|
@ -139,8 +140,9 @@ _RUNTIME_VARS_DEFAULTS: dict[str, Any] = {
|
|||
# `debug_mode: bool` settings
|
||||
'_debug_mode': False, # bool
|
||||
'repl_fixture': False, # |AbstractContextManager[bool]
|
||||
# for `tractor.pause_from_sync()` & `breakpoint()` support
|
||||
'use_greenback': False,
|
||||
|
||||
'use_greenback': False, # `.pause_from_sync()`/`breakpoint()`
|
||||
'use_stackscope': False, # trio-task-stack dumps on SIGUSR1
|
||||
|
||||
# infected-`asyncio`-mode: `trio` running as guest.
|
||||
'_is_infected_aio': False,
|
||||
|
|
|
|||
Loading…
Reference in New Issue