tractor/tractor/spawn/__init__.py

41 lines
1.4 KiB
Python
Raw Normal View History

# tractor: structured concurrent "actors".
# Copyright 2018-eternity Tyler Goodlet.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
Actor process spawning machinery using multiple backends.
- `._spawn`: cross-backend subactor-as-sub[proc|int] spawning
and supervision routines.
Per-backend submodules (each exposes a single `*_proc()`
coroutine registered in `_spawn._methods`):
- `._trio`: the `trio`-native subprocess backend (default,
all platforms), spawns via `trio.lowlevel.open_process()`.
- `._mp`: the stdlib `multiprocessing` backend variants driven by
the `mp.context` bound to `_spawn._ctx`:
* `'mp_spawn'`,
Restore fn-arg `_runtime_vars` in `trio_proc` teardown During the Phase A extraction of `trio_proc()` out of `spawn._spawn` into its own submod, the `debug.maybe_wait_for_debugger(child_in_debug=...)` call site in the hard-reap `finally` got refactored from the original `_runtime_vars.get('_debug_mode', ...)` (the fn parameter — the dict that was constructed by the *parent* for the *child*'s `SpawnSpec`) to `get_runtime_vars().get(...)` (a global getter that returns the *parent's* live `_state`). Those are semantically different — the first asks "is the child we just spawned in debug mode?", the second asks "are *we* in debug mode?". Under mixed-debug-mode trees the swap can incorrectly skip (or unnecessarily delay) the debugger-lock wait during teardown. Revert to the fn-parameter lookup and add an inline `NOTE` comment calling out the distinction so it's harder to regress again. Deats, - `spawn/_trio.py`: `child_in_debug=get_runtime_vars().get(...)` → `child_in_debug=_runtime_vars.get(...)` at the `debug.maybe_wait_for_debugger(...)` call in the hard-reap block; add 4-line `NOTE` explaining the parent-vs-child distinction. - `spawn/__init__.py`: drop trailing whitespace after the `'mp_forkserver'` docstring bullet. - `ai/prompt-io/prompts/subints_spawner.md`: drop duplicated `with` in `"as with with subprocs"` prose (copilot grammar catch). Review: PR #444 (Copilot) https://github.com/goodboy/tractor/pull/444#pullrequestreview-4165928469 (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
2026-04-23 22:30:11 +00:00
* `'mp_forkserver'`
Entry-point helpers live in `._entry`/`._mp_fixup_main`/
`._forkserver_override`.
NOTE: to avoid circular imports, this ``__init__`` does NOT eagerly
import submodules.
'''