Compare commits
152 Commits
5e5d785b8a
...
d6e3351372
| Author | SHA1 | Date |
|---|---|---|
|
|
d6e3351372 | |
|
|
3a5ad5a4a0 | |
|
|
cf56cb60ed | |
|
|
ee79939dd3 | |
|
|
a82607f3f9 | |
|
|
70a6f61bdc | |
|
|
bcad6b090e | |
|
|
5dfb3df8f5 | |
|
|
6683e3ffa4 | |
|
|
5bad5bdd10 | |
|
|
4c186f8d5e | |
|
|
a722d535d9 | |
|
|
90466ec016 | |
|
|
2fdf3901cb | |
|
|
084f0fc404 | |
|
|
c797bcb783 | |
|
|
7b518fe4e1 | |
|
|
b0ac681245 | |
|
|
fdac157d3d | |
|
|
d28173f4c0 | |
|
|
f08a7d52b5 | |
|
|
41b5371473 | |
|
|
6d45581910 | |
|
|
6a7dea45bb | |
|
|
fa0208e65f | |
|
|
b6bf865f5e | |
|
|
8bb9df9e06 | |
|
|
944262d8a6 | |
|
|
b57d095204 | |
|
|
4b70b564c8 | |
|
|
da582a4d1b | |
|
|
30242d03fb | |
|
|
fad1227d7c | |
|
|
c8a77fb92b | |
|
|
68698afac7 | |
|
|
98522661d6 | |
|
|
dfe853e159 | |
|
|
f0a1971814 | |
|
|
46c1147f6e | |
|
|
da2d5bb3d2 | |
|
|
36ad56843e | |
|
|
acb042ec77 | |
|
|
75c87831cb | |
|
|
105f0c2944 | |
|
|
48a0f2fc49 | |
|
|
d70e003184 | |
|
|
aced458350 | |
|
|
42881b3d38 | |
|
|
f5940de5c0 | |
|
|
9f9a536fa9 | |
|
|
f0b944f8db | |
|
|
5f2e89ed1f | |
|
|
3c6ea8009b | |
|
|
338f0a1463 | |
|
|
6b14c3dbe7 | |
|
|
2cd668dcc8 | |
|
|
9426fea5bd | |
|
|
e9b63e8569 | |
|
|
4c600dc528 | |
|
|
254a46c345 | |
|
|
f500bebbe6 | |
|
|
a0456fece4 | |
|
|
0c64e76bf9 | |
|
|
84d52835ab | |
|
|
cc5be294b1 | |
|
|
d8a398f6f5 | |
|
|
e873bb6164 | |
|
|
63c6da9e82 | |
|
|
272b6686ae | |
|
|
797d6cf4fa | |
|
|
98fdaf343d | |
|
|
73c9b9ec93 | |
|
|
a4f6d893ed | |
|
|
8589a796c1 | |
|
|
afa14b01d2 | |
|
|
836270e995 | |
|
|
02177d96c4 | |
|
|
b13d06af80 | |
|
|
99098c5a14 | |
|
|
158506d8c0 | |
|
|
e1da7be4d9 | |
|
|
af72192461 | |
|
|
831cb6fcf0 | |
|
|
80048ff6ad | |
|
|
f9e64d0035 | |
|
|
5d37acb5b8 | |
|
|
d4eac06de2 | |
|
|
950b6bc6b8 | |
|
|
c31b85587a | |
|
|
1d185e4d94 | |
|
|
dacd7a7c57 | |
|
|
c603a6e1a0 | |
|
|
3954d9f527 | |
|
|
13ccbaff60 | |
|
|
ec5141b720 | |
|
|
d24ccaada1 | |
|
|
f7a58b82fe | |
|
|
149e1e1993 | |
|
|
a4554106fc | |
|
|
d5a15b4d70 | |
|
|
e5ca5bb017 | |
|
|
0b6a7aa1a9 | |
|
|
50392e6e78 | |
|
|
f633ebf5c6 | |
|
|
48ace6dd82 | |
|
|
04ffde40f3 | |
|
|
18754f2570 | |
|
|
e70ef50a0c | |
|
|
f68ae75444 | |
|
|
af0b1fb2dc | |
|
|
6bf8364c16 | |
|
|
d328177873 | |
|
|
662a34b994 | |
|
|
353fb82c36 | |
|
|
21b17b6a40 | |
|
|
d5c549a3c3 | |
|
|
239c3fb14d | |
|
|
6afeb6b6ef | |
|
|
b2cc4f502c | |
|
|
fd4caa1903 | |
|
|
253b210bcd | |
|
|
f7dfd37df4 | |
|
|
4b63b7f1cc | |
|
|
54a694d452 | |
|
|
eb3e2b3574 | |
|
|
26f2b23da2 | |
|
|
c0fdfa4c7b | |
|
|
c5feeac4ce | |
|
|
9f1a64fcf7 | |
|
|
6b0cb17c04 | |
|
|
dd651943d1 | |
|
|
cec0731253 | |
|
|
9defec4922 | |
|
|
0a3772c0c1 | |
|
|
3f18caaaac | |
|
|
3dc3f8401c | |
|
|
8c6b7fdb31 | |
|
|
4e9f392ca3 | |
|
|
cda94235f4 | |
|
|
a26619dfea | |
|
|
974cb159e8 | |
|
|
c170007ddc | |
|
|
fc3ab9561b | |
|
|
e5d4d9494b | |
|
|
47ac8c0fef | |
|
|
ba111b3042 | |
|
|
e8e4657e6d | |
|
|
c72dc8c235 | |
|
|
fae2525461 | |
|
|
dca79670aa | |
|
|
bca7f10915 | |
|
|
61f9b62d04 |
|
|
@ -0,0 +1,125 @@
|
|||
# `RuntimeVars` env-var lift — design plan
|
||||
|
||||
Status: **draft, awaiting user edits**
|
||||
|
||||
## Goal
|
||||
|
||||
Consolidate the sprawl of pytest CLI flags + ad-hoc env vars +
|
||||
hardcoded fixture defaults into a *single* env-var-encoded
|
||||
runtime-vars envelope, with a typed in-memory representation
|
||||
(`tractor.runtime._state.RuntimeVars`) as the sole source of
|
||||
truth.
|
||||
|
||||
## Why now
|
||||
|
||||
- `--tpt-proto`, `--spawn-backend`, `--diag-on-hang`,
|
||||
`--diag-capture-delay` and (soon) `TRACTOR_REG_ADDR` etc. are
|
||||
proliferating. Each adds a parsing seam.
|
||||
- `tests/devx/test_debugger.py` invokes example scripts as
|
||||
separate subprocesses; they currently can't see the
|
||||
fixture-allocated `reg_addr` at all (root cause of why
|
||||
parametrizing devx scripts on `reg_addr` is on your TODO).
|
||||
- Concurrent pytest sessions on the same host collide on
|
||||
shared defaults (the `registry@1616` race we just fixed is
|
||||
one symptom; per-session unique addr is the structural
|
||||
fix).
|
||||
- `tractor.runtime._state.RuntimeVars: Struct` is already
|
||||
defined and **unused** — its docstring even says it
|
||||
"should be utilized as possible for future calls."
|
||||
|
||||
## Design
|
||||
|
||||
### Module: `tractor/_testing/_rtvars.py`
|
||||
|
||||
Lifted from `modden.runtime.env`, ~50 LOC, no new deps.
|
||||
|
||||
```python
|
||||
_TRACTOR_RT_VARS_OSENV: str = '_TRACTOR_RT_VARS'
|
||||
|
||||
def dump_rtvars(rtvars: RuntimeVars|dict) -> tuple[str, str]:
|
||||
'''str-serialize via `str(dict)` — ast.literal_eval-able'''
|
||||
|
||||
def load_rtvars(env: dict) -> RuntimeVars:
|
||||
'''ast.literal_eval the env-var value, hydrate to struct'''
|
||||
|
||||
def get_rtvars(proc: psutil.Process|None = None) -> RuntimeVars:
|
||||
'''read the var from a target proc's env (or current)'''
|
||||
|
||||
def update_rtvars(
|
||||
rtvars: RuntimeVars|dict|None = None,
|
||||
update_osenv: bool|dict = True,
|
||||
) -> tuple[str, str]:
|
||||
'''mutate + re-encode + (optionally) write to os.environ'''
|
||||
```
|
||||
|
||||
### Encoding choice: `str(dict)` + `ast.literal_eval`
|
||||
|
||||
Pros:
|
||||
- stdlib only
|
||||
- handles all the types tractor's tests need: `str`, `int`,
|
||||
`float`, `bool`, `None`, `list`, `tuple`, `dict`
|
||||
- human-readable in the env (greppable, inspectable via
|
||||
`cat /proc/<pid>/environ | tr '\0' '\n'`)
|
||||
|
||||
Cons:
|
||||
- non-stdlib types (msgspec Structs, `Path`, custom classes)
|
||||
must be lowered first — fine for the test fixture set
|
||||
- not stable across Python versions for esoteric repr cases
|
||||
(we don't hit any)
|
||||
|
||||
Alternatives considered:
|
||||
- **msgpack**: adds a dep + binary form is ungreppable
|
||||
- **json**: doesn't preserve tuples (becomes lists), which is
|
||||
a common type for `reg_addr`
|
||||
- **toml/yaml**: heavier deps, no real benefit
|
||||
|
||||
### `RuntimeVars` becomes the single source of truth
|
||||
|
||||
The legacy `_runtime_vars: dict[str, Any]` global in
|
||||
`runtime/_state.py` becomes a *cached view* of a
|
||||
`RuntimeVars` singleton instance:
|
||||
|
||||
- `get_runtime_vars()` returns either the struct or a
|
||||
`.to_dict()` view depending on caller's preference
|
||||
- `set_runtime_vars(...)` validates against the struct schema
|
||||
- spawn-time SpawnSpec sends the struct (already does
|
||||
conceptually — just gets typed)
|
||||
- `__setattr__` `breakpoint()` debug instrumentation gets
|
||||
removed (unrelated cleanup, mentioned in conversation)
|
||||
|
||||
### Migration path
|
||||
|
||||
**Phase 0** *(prep)*: strip the stray `breakpoint()` from
|
||||
`RuntimeVars.__setattr__`.
|
||||
|
||||
**Phase 1**: land `_rtvars.py` as a leaf module, used only by
|
||||
test infra. Subprocess-spawned scripts in `tests/devx/`
|
||||
read `_TRACTOR_RT_VARS` on startup → reconstruct
|
||||
`RuntimeVars` → call `tractor.open_root_actor(**rtvars.as_kwargs())`.
|
||||
Concurrent runs become deterministic-isolated because each
|
||||
session writes a unique `_registry_addrs` into the env.
|
||||
|
||||
**Phase 2**: migrate runtime callers (`_state.get_runtime_vars`,
|
||||
spawn `SpawnSpec`, `Actor.async_main`) to operate on the
|
||||
struct directly, with the dict as a compat view that gets
|
||||
deprecated.
|
||||
|
||||
**Phase 3** *(structural)*: per-session bindspace subdir
|
||||
`/run/user/<uid>/tractor/<session_uuid>/` — encoded in the
|
||||
rt-vars envelope, picked up by every subactor automatically.
|
||||
Obsoletes the entire bindspace-leak warning class.
|
||||
|
||||
## Open design questions (user input wanted)
|
||||
|
||||
- (placeholder for your edits)
|
||||
- (placeholder)
|
||||
- (placeholder)
|
||||
|
||||
## Out-of-scope for this lift
|
||||
|
||||
- Anything in `modden.runtime.env` related to `Spawn`,
|
||||
`WmCtl`, `Wks` — that's a workspace orchestration layer,
|
||||
not an env-var helper. We only lift the four utility
|
||||
functions + the var name constant.
|
||||
- Switching to msgpack/json — explicitly chosen against
|
||||
above.
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(date *)",
|
||||
"Bash(cp .claude/*)",
|
||||
"Read(.claude/**)",
|
||||
"Read(.claude/skills/run-tests/**)",
|
||||
"Write(.claude/**/*commit_msg*)",
|
||||
"Write(.claude/git_commit_msg_LATEST.md)",
|
||||
"Skill(run-tests)",
|
||||
"Skill(close-wkt)",
|
||||
"Skill(open-wkt)",
|
||||
"Skill(prompt-io)",
|
||||
"Bash(date *)",
|
||||
"Bash(git diff *)",
|
||||
"Bash(git log *)",
|
||||
"Bash(git status)",
|
||||
|
|
@ -23,14 +31,12 @@
|
|||
"Bash(UV_PROJECT_ENVIRONMENT=py* uv sync:*)",
|
||||
"Bash(UV_PROJECT_ENVIRONMENT=py* uv run:*)",
|
||||
"Bash(echo EXIT:$?:*)",
|
||||
"Write(.claude/*commit_msg*)",
|
||||
"Write(.claude/git_commit_msg_LATEST.md)",
|
||||
"Skill(run-tests)",
|
||||
"Skill(close-wkt)",
|
||||
"Skill(open-wkt)",
|
||||
"Skill(prompt-io)"
|
||||
"Bash(echo \"EXIT=$?\")",
|
||||
"Read(/tmp/**)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
}
|
||||
},
|
||||
"prefersReducedMotion": false,
|
||||
"outputStyle": "default"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,3 +229,69 @@ Unlike asyncio, trio allows checkpoints in
|
|||
that does `await` can itself be cancelled (e.g.
|
||||
by nursery shutdown). Watch for cleanup code that
|
||||
assumes it will run to completion.
|
||||
|
||||
### Unbounded waits in cleanup paths
|
||||
|
||||
Any `await <event>.wait()` in a teardown path is
|
||||
a latent deadlock unless the event's setter is
|
||||
GUARANTEED to fire. If the setter depends on
|
||||
external state (peer disconnects, child process
|
||||
exit, subsequent task completion) that itself
|
||||
depends on the current task's progress, you have
|
||||
a mutual wait.
|
||||
|
||||
Rule: **bound every `await X.wait()` in cleanup
|
||||
paths with `trio.move_on_after()`** unless you
|
||||
can prove the setter is unconditionally reachable
|
||||
from the state at the await site. Concrete recent
|
||||
example: `ipc_server.wait_for_no_more_peers()` in
|
||||
`async_main`'s finally (see
|
||||
`ai/conc-anal/subint_forkserver_test_cancellation_leak_issue.md`
|
||||
"probe iteration 3") — it was unbounded, and when
|
||||
one peer-handler was stuck the wait-for-no-more-
|
||||
peers event never fired, deadlocking the whole
|
||||
actor-tree teardown cascade.
|
||||
|
||||
### The capture-pipe-fill hang pattern (grep this first)
|
||||
|
||||
When investigating any hang in the test suite
|
||||
**especially under fork-based backends**, first
|
||||
check whether the hang reproduces under `pytest
|
||||
-s` (`--capture=no`). If `-s` makes it go away
|
||||
you're not looking at a trio concurrency bug —
|
||||
you're looking at a Linux pipe-buffer fill.
|
||||
|
||||
Mechanism: pytest replaces fds 1,2 with pipe
|
||||
write-ends. Fork-child subactors inherit those
|
||||
fds. High-volume error-log tracebacks (cancel
|
||||
cascade spew) fill the 64KB pipe buffer. Child
|
||||
`write()` blocks. Child can't exit. Parent's
|
||||
`waitpid`/pidfd wait blocks. Deadlock cascades up
|
||||
the tree.
|
||||
|
||||
Pre-existing guards in `tests/conftest.py` encode
|
||||
this knowledge — grep these BEFORE blaming
|
||||
concurrency:
|
||||
|
||||
```python
|
||||
# tests/conftest.py:258
|
||||
if loglevel in ('trace', 'debug'):
|
||||
# XXX: too much logging will lock up the subproc (smh)
|
||||
loglevel: str = 'info'
|
||||
|
||||
# tests/conftest.py:316
|
||||
# can lock up on the `_io.BufferedReader` and hang..
|
||||
stderr: str = proc.stderr.read().decode()
|
||||
```
|
||||
|
||||
Full post-mortem +
|
||||
`ai/conc-anal/subint_forkserver_test_cancellation_leak_issue.md`
|
||||
for the canonical reproduction. Cost several
|
||||
investigation sessions before catching it —
|
||||
because the capture-pipe symptom was masked by
|
||||
deeper cascade-deadlocks. Once the cascades were
|
||||
fixed, the tree tore down enough to generate
|
||||
pipe-filling log volume → capture-pipe finally
|
||||
surfaced. Grep-note for future-self: **if a
|
||||
multi-subproc tractor test hangs, `pytest -s`
|
||||
first, conc-anal second.**
|
||||
|
|
|
|||
|
|
@ -8,14 +8,26 @@ allowed-tools:
|
|||
- Bash(python -m pytest *)
|
||||
- Bash(python -c *)
|
||||
- Bash(python --version *)
|
||||
- Bash(git rev-parse *)
|
||||
- Bash(UV_PROJECT_ENVIRONMENT=py* uv run python *)
|
||||
- Bash(UV_PROJECT_ENVIRONMENT=py* uv run pytest *)
|
||||
- Bash(UV_PROJECT_ENVIRONMENT=py* uv sync *)
|
||||
- Bash(UV_PROJECT_ENVIRONMENT=py* uv pip show *)
|
||||
- Bash(git rev-parse *)
|
||||
- Bash(ls *)
|
||||
- Bash(cat *)
|
||||
- Bash(jq * .pytest_cache/*)
|
||||
# process inspection + SIGINT-first cleanup ladder (see
|
||||
# the zombie-actor pre-flight / teardown steps below).
|
||||
- Bash(ss *)
|
||||
- Bash(pgrep *)
|
||||
- Bash(pkill *)
|
||||
- Bash(sleep *)
|
||||
- Bash(rm -f /tmp/registry@*.sock)
|
||||
- Read
|
||||
- Grep
|
||||
- Glob
|
||||
- Task
|
||||
- AskUserQuestion
|
||||
---
|
||||
|
||||
Run the `tractor` test suite using `pytest`. Follow this
|
||||
|
|
@ -90,41 +102,104 @@ python -m pytest tests/ -x --tb=short --no-header --tpt-proto uds
|
|||
python -m pytest tests/ -x --tb=short --no-header -k "cancel and not slow"
|
||||
```
|
||||
|
||||
## 3. Pre-flight checks (before running tests)
|
||||
## 3. Pre-flight: venv detection (MANDATORY)
|
||||
|
||||
### Worktree venv detection
|
||||
**Always verify a `uv` venv is active before running
|
||||
`python` or `pytest`.** This project uses
|
||||
`UV_PROJECT_ENVIRONMENT=py<MINOR>` naming (e.g.
|
||||
`py313`) — never `.venv`.
|
||||
|
||||
If running inside a git worktree (`git rev-parse
|
||||
--git-common-dir` differs from `--git-dir`), verify
|
||||
the Python being used is from the **worktree's own
|
||||
venv**, not the main repo's. Check:
|
||||
### Step 1: detect active venv
|
||||
|
||||
Run this check first:
|
||||
|
||||
```sh
|
||||
python -c "
|
||||
import sys, os
|
||||
venv = os.environ.get('VIRTUAL_ENV', '')
|
||||
prefix = sys.prefix
|
||||
print(f'VIRTUAL_ENV={venv}')
|
||||
print(f'sys.prefix={prefix}')
|
||||
print(f'executable={sys.executable}')
|
||||
"
|
||||
```
|
||||
|
||||
### Step 2: interpret results
|
||||
|
||||
**Case A — venv is active** (`VIRTUAL_ENV` is set
|
||||
and points to a `py<MINOR>/` dir under the project
|
||||
root or worktree):
|
||||
|
||||
Use bare `python` / `python -m pytest` for all
|
||||
commands. This is the normal, fast path.
|
||||
|
||||
**Case B — no venv active** (`VIRTUAL_ENV` is empty
|
||||
or `sys.prefix` points to a system Python):
|
||||
|
||||
Use `AskUserQuestion` to ask the user:
|
||||
|
||||
> "No uv venv is active. Should I activate one
|
||||
> via `UV_PROJECT_ENVIRONMENT=py<MINOR> uv sync`,
|
||||
> or would you prefer to activate your shell venv
|
||||
> first?"
|
||||
|
||||
Options:
|
||||
1. **"Create/sync venv"** — run
|
||||
`UV_PROJECT_ENVIRONMENT=py<MINOR> uv sync` where
|
||||
`<MINOR>` is detected from `python --version`
|
||||
(e.g. `313` for 3.13). Then use
|
||||
`py<MINOR>/bin/python` for all subsequent
|
||||
commands in this session.
|
||||
2. **"I'll activate it myself"** — stop and let the
|
||||
user `source py<MINOR>/bin/activate` or similar.
|
||||
|
||||
**Case C — inside a git worktree** (`git rev-parse
|
||||
--git-common-dir` differs from `--git-dir`):
|
||||
|
||||
Verify Python resolves from the **worktree's own
|
||||
venv**, not the main repo's:
|
||||
|
||||
```sh
|
||||
python -c "import tractor; print(tractor.__file__)"
|
||||
```
|
||||
|
||||
If the path points outside the worktree (e.g. to
|
||||
the main repo), set up a local venv first:
|
||||
If the path points outside the worktree, create a
|
||||
worktree-local venv:
|
||||
|
||||
```sh
|
||||
UV_PROJECT_ENVIRONMENT=py<MINOR> uv sync
|
||||
```
|
||||
|
||||
where `<MINOR>` matches the active cpython minor
|
||||
version (detect via `python --version`, e.g.
|
||||
`py313` for 3.13, `py314` for 3.14). Then use
|
||||
`py<MINOR>/bin/python` for all subsequent commands.
|
||||
Then use `py<MINOR>/bin/python` for all commands.
|
||||
|
||||
**Why this matters**: without a worktree-local venv,
|
||||
subprocesses spawned by tractor resolve modules from
|
||||
the main repo's editable install, causing spurious
|
||||
`AttributeError` / `ModuleNotFoundError` for code
|
||||
that only exists on the worktree's branch.
|
||||
**Why this matters**: without the correct venv,
|
||||
subprocesses spawned by tractor resolve modules
|
||||
from the wrong editable install, causing spurious
|
||||
`AttributeError` / `ModuleNotFoundError`.
|
||||
|
||||
### Import + collection checks
|
||||
### Fallback: `uv run`
|
||||
|
||||
Always run these, especially after refactors or
|
||||
module moves — they catch import errors instantly:
|
||||
If the user can't or won't activate a venv, all
|
||||
`python` and `pytest` commands can be prefixed
|
||||
with `UV_PROJECT_ENVIRONMENT=py<MINOR> uv run`:
|
||||
|
||||
```sh
|
||||
# instead of: python -m pytest tests/ -x
|
||||
UV_PROJECT_ENVIRONMENT=py313 uv run pytest tests/ -x
|
||||
|
||||
# instead of: python -c 'import tractor'
|
||||
UV_PROJECT_ENVIRONMENT=py313 uv run python -c 'import tractor'
|
||||
```
|
||||
|
||||
`uv run` auto-discovers the project and venv,
|
||||
but is slower than a pre-activated venv due to
|
||||
lock-file resolution on each invocation. Prefer
|
||||
activating the venv when possible.
|
||||
|
||||
### Step 3: import + collection checks
|
||||
|
||||
After venv is confirmed, always run these
|
||||
(especially after refactors or module moves):
|
||||
|
||||
```sh
|
||||
# 1. package import smoke check
|
||||
|
|
@ -137,6 +212,101 @@ python -m pytest tests/ -x -q --co 2>&1 | tail -5
|
|||
If either fails, fix the import error before running
|
||||
any actual tests.
|
||||
|
||||
### Step 4: zombie-actor / stale-registry check (MANDATORY)
|
||||
|
||||
The tractor runtime's default registry address is
|
||||
**`127.0.0.1:1616`** (TCP) / `/tmp/registry@1616.sock`
|
||||
(UDS). Whenever any prior test run — especially one
|
||||
using a fork-based backend like `subint_forkserver` —
|
||||
leaks a child actor process, that zombie keeps the
|
||||
registry port bound and **every subsequent test
|
||||
session fails to bind**, often presenting as 50+
|
||||
unrelated failures ("all tests broken"!) across
|
||||
backends.
|
||||
|
||||
**This has to be checked before the first run AND
|
||||
after any cancelled/SIGINT'd run** — signal failures
|
||||
in the middle of a test can leave orphan children.
|
||||
|
||||
```sh
|
||||
# 1. TCP registry — any listener on :1616? (primary signal)
|
||||
ss -tlnp 2>/dev/null | grep ':1616' || echo 'TCP :1616 free'
|
||||
|
||||
# 2. leftover actor/forkserver procs — scoped to THIS
|
||||
# repo's python path, so we don't false-flag legit
|
||||
# long-running tractor-using apps (e.g. `piker`,
|
||||
# downstream projects that embed tractor).
|
||||
pgrep -af "$(pwd)/py[0-9]*/bin/python.*_actor_child_main|subint-forkserv" \
|
||||
| grep -v 'grep\|pgrep' \
|
||||
|| echo 'no leaked actor procs from this repo'
|
||||
|
||||
# 3. stale UDS registry sockets
|
||||
ls -la /tmp/registry@*.sock 2>/dev/null \
|
||||
|| echo 'no leaked UDS registry sockets'
|
||||
```
|
||||
|
||||
**Interpretation:**
|
||||
|
||||
- **TCP :1616 free AND no stale sockets** → clean,
|
||||
proceed. The actor-procs probe is secondary — false
|
||||
positives are common (piker, any other tractor-
|
||||
embedding app); only cleanup if `:1616` is bound or
|
||||
sockets linger.
|
||||
- **TCP :1616 bound OR stale sockets present** →
|
||||
surface PIDs + cmdlines to the user, offer cleanup:
|
||||
|
||||
```sh
|
||||
# 1. GRACEFUL FIRST (tractor is structured concurrent — it
|
||||
# catches SIGINT as an OS-cancel in `_trio_main` and
|
||||
# cascades Portal.cancel_actor via IPC to every descendant.
|
||||
# So always try SIGINT first with a bounded timeout; only
|
||||
# escalate to SIGKILL if graceful cleanup doesn't complete).
|
||||
pkill -INT -f "$(pwd)/py[0-9]*/bin/python.*_actor_child_main|subint-forkserv"
|
||||
|
||||
# 2. bounded wait for graceful teardown (usually sub-second).
|
||||
# Loop until the processes exit, or timeout. Keep the
|
||||
# bound tight — hung/abrupt-killed descendants usually
|
||||
# hang forever, so don't wait more than a few seconds.
|
||||
for i in $(seq 1 10); do
|
||||
pgrep -f "$(pwd)/py[0-9]*/bin/python.*_actor_child_main|subint-forkserv" >/dev/null || break
|
||||
sleep 0.3
|
||||
done
|
||||
|
||||
# 3. ESCALATE TO SIGKILL only if graceful didn't finish.
|
||||
if pgrep -f "$(pwd)/py[0-9]*/bin/python.*_actor_child_main|subint-forkserv" >/dev/null; then
|
||||
echo 'graceful teardown timed out — escalating to SIGKILL'
|
||||
pkill -9 -f "$(pwd)/py[0-9]*/bin/python.*_actor_child_main|subint-forkserv"
|
||||
fi
|
||||
|
||||
# 4. if a test zombie holds :1616 specifically and doesn't
|
||||
# match the above pattern, find its PID the hard way:
|
||||
ss -tlnp 2>/dev/null | grep ':1616' # prints `users:(("<name>",pid=NNNN,...))`
|
||||
# then (same SIGINT-first ladder):
|
||||
# kill -INT <NNNN>; sleep 1; kill -9 <NNNN> 2>/dev/null
|
||||
|
||||
# 5. remove stale UDS sockets
|
||||
rm -f /tmp/registry@*.sock
|
||||
|
||||
# 6. re-verify
|
||||
ss -tlnp 2>/dev/null | grep ':1616' || echo 'TCP :1616 now free'
|
||||
```
|
||||
|
||||
**Never ignore stale registry state.** If you see the
|
||||
"all tests failing" pattern — especially
|
||||
`trio.TooSlowError` / connection refused / address in
|
||||
use on many unrelated tests — check registry **before**
|
||||
spelunking into test code. The failure signature will
|
||||
be identical across backends because they're all
|
||||
fighting for the same port.
|
||||
|
||||
**False-positive warning for step 2:** a plain
|
||||
`pgrep -af '_actor_child_main'` will also match
|
||||
legit long-running tractor-embedding apps (e.g.
|
||||
`piker` at `~/repos/piker/py*/bin/python3 -m
|
||||
tractor._child ...`). Always scope to the current
|
||||
repo's python path, or only use step 1 (`:1616`) as
|
||||
the authoritative signal.
|
||||
|
||||
## 4. Run and report
|
||||
|
||||
- Run the constructed command.
|
||||
|
|
@ -217,7 +387,48 @@ python -c 'import tractor' && python -m pytest tests/ -x -q --co 2>&1 | tail -3
|
|||
python -m pytest tests/test_local.py tests/test_rpc.py tests/test_spawning.py tests/discovery/test_registrar.py -x --tb=short --no-header
|
||||
```
|
||||
|
||||
### Re-run last failures only:
|
||||
### Inspect last failures (without re-running):
|
||||
|
||||
When the user asks "what failed?", "show failures",
|
||||
or wants to check the last-failed set before
|
||||
re-running — read the pytest cache directly. This
|
||||
is instant and avoids test collection overhead.
|
||||
|
||||
```sh
|
||||
python -c "
|
||||
import json, pathlib, sys
|
||||
p = pathlib.Path('.pytest_cache/v/cache/lastfailed')
|
||||
if not p.exists():
|
||||
print('No lastfailed cache found.'); sys.exit()
|
||||
data = json.loads(p.read_text())
|
||||
# filter to real test node IDs (ignore junk
|
||||
# entries that can accumulate from system paths)
|
||||
tests = sorted(k for k in data if k.startswith('tests/'))
|
||||
if not tests:
|
||||
print('No failures recorded.')
|
||||
else:
|
||||
print(f'{len(tests)} last-failed test(s):')
|
||||
for t in tests:
|
||||
print(f' {t}')
|
||||
"
|
||||
```
|
||||
|
||||
**Why not `--cache-show` or `--co --lf`?**
|
||||
|
||||
- `pytest --cache-show 'cache/lastfailed'` works
|
||||
but dumps raw dict repr including junk entries
|
||||
(stale system paths that leak into the cache).
|
||||
- `pytest --co --lf` actually *collects* tests which
|
||||
triggers import resolution and is slow (~0.5s+).
|
||||
Worse, when cached node IDs don't exactly match
|
||||
current parametrize IDs (e.g. param names changed
|
||||
between runs), pytest falls back to collecting
|
||||
the *entire file*, giving false positives.
|
||||
- Reading the JSON directly is instant, filterable
|
||||
to `tests/`-prefixed entries, and shows exactly
|
||||
what pytest recorded — no interpretation.
|
||||
|
||||
**After inspecting**, re-run the failures:
|
||||
```sh
|
||||
python -m pytest --lf -x --tb=short --no-header
|
||||
```
|
||||
|
|
@ -247,3 +458,175 @@ by your changes — note them and move on.
|
|||
**Rule of thumb**: if a test fails with `TooSlowError`,
|
||||
`trio.TooSlowError`, or `pexpect.TIMEOUT` and you didn't
|
||||
touch the relevant code path, it's flaky — skip it.
|
||||
|
||||
## 9. The pytest-capture hang pattern (CHECK THIS FIRST)
|
||||
|
||||
**Symptom:** a tractor test hangs indefinitely under
|
||||
default `pytest` but passes instantly when you add
|
||||
`-s` (`--capture=no`).
|
||||
|
||||
**Cause:** tractor subactors (especially under fork-
|
||||
based backends) inherit pytest's stdout/stderr
|
||||
capture pipes via fds 1,2. Under high-volume error
|
||||
logging (e.g. multi-level cancel cascade, nested
|
||||
`run_in_actor` failures, anything triggering
|
||||
`RemoteActorError` + `ExceptionGroup` traceback
|
||||
spew), the **64KB Linux pipe buffer fills** faster
|
||||
than pytest drains it. Subactor writes block → can't
|
||||
finish exit → parent's `waitpid`/pidfd wait blocks →
|
||||
deadlock cascades up the tree.
|
||||
|
||||
**Pre-existing guards in the tractor harness** that
|
||||
encode this same knowledge — grep these FIRST
|
||||
before spelunking:
|
||||
|
||||
- `tests/conftest.py:258-260` (in the `daemon`
|
||||
fixture): `# XXX: too much logging will lock up
|
||||
the subproc (smh)` — downgrades `trace`/`debug`
|
||||
loglevel to `info` to prevent the hang.
|
||||
- `tests/conftest.py:316`: `# can lock up on the
|
||||
_io.BufferedReader and hang..` — noted on the
|
||||
`proc.stderr.read()` post-SIGINT.
|
||||
|
||||
**Debug recipe (in priority order):**
|
||||
|
||||
1. **Try `-s` first.** If the hang disappears with
|
||||
`pytest -s`, you've confirmed it's capture-pipe
|
||||
fill. Skip spelunking.
|
||||
2. **Lower the loglevel.** Default `--ll=error` on
|
||||
this project; if you've bumped it to `debug` /
|
||||
`info`, try dropping back. Each log level
|
||||
multiplies pipe-pressure under fault cascades.
|
||||
3. **If you MUST use default capture + high log
|
||||
volume**, redirect subactor stdout/stderr in the
|
||||
child prelude (e.g.
|
||||
`tractor.spawn._subint_forkserver._child_target`
|
||||
post-`_close_inherited_fds`) to `/dev/null` or a
|
||||
file.
|
||||
|
||||
**Signature tells you it's THIS bug (vs. a real
|
||||
code hang):**
|
||||
|
||||
- Multi-actor test under fork-based backend
|
||||
(`subint_forkserver`, eventually `trio_proc` too
|
||||
under enough log volume).
|
||||
- Multiple `RemoteActorError` / `ExceptionGroup`
|
||||
tracebacks in the error path.
|
||||
- Test passes with `-s` in the 5-10s range, hangs
|
||||
past pytest-timeout (usually 30+ s) without `-s`.
|
||||
- Subactor processes visible via `pgrep -af
|
||||
subint-forkserv` or similar after the hang —
|
||||
they're alive but blocked on `write()` to an
|
||||
inherited stdout fd.
|
||||
|
||||
**Historical reference:** this deadlock cost a
|
||||
multi-session investigation (4 genuine cascade
|
||||
fixes landed along the way) that only surfaced the
|
||||
capture-pipe issue AFTER the deeper fixes let the
|
||||
tree actually tear down enough to produce pipe-
|
||||
filling log volume. Full post-mortem in
|
||||
`ai/conc-anal/subint_forkserver_test_cancellation_leak_issue.md`.
|
||||
Lesson codified here so future-me grep-finds the
|
||||
workaround before digging.
|
||||
|
||||
## 10. Reaping zombie subactors (`tractor-reap`)
|
||||
|
||||
**Symptom:** after a `pytest` run crashes, times out,
|
||||
or is `Ctrl+C`'d, subactor forks (esp. under
|
||||
`subint_forkserver`) can be reparented to `init`
|
||||
(PPid==1) and linger. They hold onto ports, inherit
|
||||
pytest's capture-pipe fds, and flakify later
|
||||
sessions.
|
||||
|
||||
**Two layers of defense:**
|
||||
|
||||
### a) Session-scoped auto-fixture (always on)
|
||||
|
||||
`tractor/_testing/pytest.py::_reap_orphaned_subactors`
|
||||
runs at pytest session teardown. It walks `/proc` for
|
||||
direct descendants of the pytest pid, SIGINTs them,
|
||||
waits up to 3s, then SIGKILLs survivors. SC-polite:
|
||||
gives the subactor runtime a chance to run its trio
|
||||
cancel shield + IPC teardown before escalation.
|
||||
|
||||
This is *autouse* and session-scoped — you don't need
|
||||
to do anything. It just runs.
|
||||
|
||||
### b) `scripts/tractor-reap` CLI (manual reap)
|
||||
|
||||
For the **pytest-died-mid-session** case (Ctrl+C, OOM
|
||||
kill, hung process you had to `kill -9`), the fixture
|
||||
never ran. Reach for the CLI:
|
||||
|
||||
```sh
|
||||
# default: orphans (PPid==1, cwd==repo, cmd contains python)
|
||||
scripts/tractor-reap
|
||||
|
||||
# descendant-mode: from a still-live supervisor
|
||||
scripts/tractor-reap --parent <pytest-pid>
|
||||
|
||||
# see what would be reaped, don't signal
|
||||
scripts/tractor-reap -n
|
||||
|
||||
# tune the SIGINT → SIGKILL grace window
|
||||
scripts/tractor-reap --grace 5
|
||||
```
|
||||
|
||||
Exit code: `0` if everyone exited on SIGINT, `1` if
|
||||
SIGKILL had to escalate — so you can chain it in CI
|
||||
health-checks (`scripts/tractor-reap || <alert>`).
|
||||
|
||||
**What it matches** (orphan-mode):
|
||||
- `PPid == 1` (reparented to init → definitely
|
||||
orphaned, not just a currently-running child)
|
||||
- `cwd == <repo-root>` (keeps the sweep scoped; won't
|
||||
touch unrelated init-children elsewhere)
|
||||
- `python` in cmdline
|
||||
|
||||
**What it does not do:** kill anything whose PPid is
|
||||
still a live tractor parent. If the parent is alive
|
||||
it's not an orphan; use `--parent <pid>` if you need
|
||||
to force-reap under a still-live supervisor.
|
||||
|
||||
**When NOT to run it:** while a pytest session is
|
||||
active in another terminal. It's safe (won't touch
|
||||
that session's live children in orphan-mode) but can
|
||||
race if the target session is mid-teardown.
|
||||
|
||||
### c) `--shm` / `--shm-only`: orphan-segment sweep
|
||||
|
||||
Because `tractor.ipc._mp_bs.disable_mantracker()`
|
||||
turns off `mp.resource_tracker` (see
|
||||
`ai/conc-anal/subint_forkserver_mp_shared_memory_issue.md`),
|
||||
a hard-crashing actor can leave `/dev/shm/<key>`
|
||||
segments behind that nothing else GCs.
|
||||
|
||||
```sh
|
||||
# process reap THEN shm sweep
|
||||
scripts/tractor-reap --shm
|
||||
|
||||
# shm sweep only (skip process phase)
|
||||
scripts/tractor-reap --shm-only
|
||||
|
||||
# dry-run: list candidates, don't unlink
|
||||
scripts/tractor-reap --shm -n
|
||||
```
|
||||
|
||||
**Match criteria** (very conservative — this is a
|
||||
shared-system path, can't be wrong):
|
||||
- segment is a regular file under `/dev/shm`,
|
||||
- owned by the **current uid** (`stat.st_uid`),
|
||||
- AND **no live process holds it open** —
|
||||
enumerated by walking every readable
|
||||
`/proc/<pid>/maps` (post-mmap mappings) AND
|
||||
`/proc/<pid>/fd/*` (pre-mmap shm-opened fds).
|
||||
|
||||
The "nobody has it open" check is the
|
||||
kernel-canonical "is this leaked?" test — same
|
||||
answer `lsof /dev/shm/<key>` would give. No
|
||||
reliance on tractor-specific naming, so it works
|
||||
for any tractor app. Critically, it WILL NOT touch
|
||||
segments held by other apps you have running
|
||||
(e.g. `piker`, `lttng-ust-*`, `aja-shm-*` —
|
||||
verified locally with 81 in-use segments correctly
|
||||
preserved).
|
||||
|
|
|
|||
|
|
@ -37,7 +37,12 @@ jobs:
|
|||
run: uv build --sdist --python=3.13
|
||||
|
||||
- name: Install sdist from .tar.gz
|
||||
run: python -m pip install dist/*.tar.gz
|
||||
# XXX must install under py3.13 (matching the build's
|
||||
# `--python=3.13`); the runner's default `python` is 3.12
|
||||
# which our `requires-python = ">=3.13"` now rejects.
|
||||
run: |
|
||||
uv venv --python 3.13
|
||||
uv pip install dist/*.tar.gz
|
||||
|
||||
# ------ type-check ------
|
||||
# mypy:
|
||||
|
|
@ -148,9 +153,12 @@ jobs:
|
|||
- name: Run tests
|
||||
run: >
|
||||
uv run
|
||||
pytest tests/ -rsx
|
||||
pytest
|
||||
tests/
|
||||
-rsx
|
||||
--spawn-backend=${{ matrix.spawn_backend }}
|
||||
--tpt-proto=${{ matrix.tpt_proto }}
|
||||
--capture=fd
|
||||
|
||||
# XXX legacy NOTE XXX
|
||||
#
|
||||
|
|
|
|||
|
|
@ -106,46 +106,55 @@ venv.bak/
|
|||
# all files under
|
||||
.git/
|
||||
|
||||
# any commit-msg gen tmp files
|
||||
.claude/skills/commit-msg/msgs/
|
||||
.claude/git_commit_msg_LATEST.md
|
||||
.claude/*_commit_*.md
|
||||
.claude/*_commit*.toml
|
||||
.claude/*_commit*.txt
|
||||
.claude/skills/commit-msg/msgs/*
|
||||
# require very explicit staging for anything we **really**
|
||||
# want put/kept in repo.
|
||||
notes_to_self/
|
||||
snippets/
|
||||
|
||||
.claude/skills/pr-msg/msgs/*
|
||||
# XXX, for rn, so i can telescope this file.
|
||||
!/.claude/skills/pr-msg/pr_msg_LATEST.md
|
||||
|
||||
# review-skill ephemeral ctx (per-PR, single-use)
|
||||
.claude/review_context.md
|
||||
.claude/review_regression.md
|
||||
|
||||
# per-skill session/conf (machine-local)
|
||||
.claude/skills/*/conf.toml
|
||||
|
||||
# ai.skillz symlinks (machine-local, deploy via deploy-skill.sh)
|
||||
# ------- AI shiz -------
|
||||
# `ai.skillz` symlinks,
|
||||
# (machine-local, deploy via deploy-skill.sh)
|
||||
.claude/skills/py-codestyle
|
||||
.claude/skills/code-review-changes
|
||||
.claude/skills/close-wkt
|
||||
.claude/skills/open-wkt
|
||||
.claude/skills/plan-io
|
||||
.claude/skills/prompt-io
|
||||
.claude/skills/resolve-conflicts
|
||||
.claude/skills/inter-skill-review
|
||||
.claude/skills/yt-url-lookup
|
||||
|
||||
# hybrid skills — symlinked SKILL.md + references
|
||||
.claude/skills/commit-msg/SKILL.md
|
||||
.claude/skills/pr-msg/SKILL.md
|
||||
.claude/skills/pr-msg/references
|
||||
# /open-wkt specifics
|
||||
.claude/skills/open-wkt
|
||||
.claude/wkts/
|
||||
claude_wkts
|
||||
|
||||
# /code-review-changes specifics
|
||||
.claude/skills/code-review-changes
|
||||
# review-skill ephemeral ctx (per-PR, single-use)
|
||||
.claude/review_context.md
|
||||
.claude/review_regression.md
|
||||
|
||||
# /pr-msg specifics
|
||||
.claude/skills/pr-msg/*
|
||||
# repo-specific
|
||||
!.claude/skills/pr-msg/format-reference.md
|
||||
# XXX, so u can nvim-telescope this file.
|
||||
# !.claude/skills/pr-msg/pr_msg_LATEST.md
|
||||
|
||||
# /commit-msg specifics
|
||||
# - any commit-msg gen tmp files
|
||||
.claude/*_commit_*.md
|
||||
.claude/*_commit*.txt
|
||||
.claude/skills/commit-msg/*
|
||||
!.claude/skills/commit-msg/style-duie-reference.md
|
||||
|
||||
# use prompt-io instead?
|
||||
.claude/plans
|
||||
|
||||
# nix develop --profile .nixdev
|
||||
.nixdev*
|
||||
|
||||
# :Obsession .
|
||||
Session.vim
|
||||
|
||||
# `gish` local `.md`-files
|
||||
# TODO? better all around automation!
|
||||
# -[ ] it'd be handy to also commit and sync with wtv git service?
|
||||
|
|
@ -159,7 +168,3 @@ gh/
|
|||
|
||||
# LLM conversations that should remain private
|
||||
docs/conversations/
|
||||
|
||||
# Claude worktrees
|
||||
.claude/wkts/
|
||||
claude_wkts
|
||||
|
|
|
|||
|
|
@ -0,0 +1,281 @@
|
|||
# `fork()` in a multi-threaded program — execution-side vs. memory-side of the same coin
|
||||
|
||||
A reference doc for readers who've encountered one of two
|
||||
opposite-sounding framings of POSIX `fork()` semantics in a
|
||||
multi-threaded program and are confused by the other.
|
||||
|
||||
This is a sibling to
|
||||
`subint_fork_blocked_by_cpython_post_fork_issue.md` — that
|
||||
doc covers a CPython-level refusal of fork-from-subint;
|
||||
this one covers the more general POSIX layer, since
|
||||
tractor's main-thread forkserver design rests on it.
|
||||
|
||||
## TL;DR
|
||||
|
||||
POSIX `fork()` only preserves the *calling* thread as a
|
||||
runnable thread in the child — every other thread in the
|
||||
parent simply never executes another instruction in the
|
||||
child. trio's docs call this "leaked"; tractor's
|
||||
`_main_thread_forkserver.py` docstring calls it "gone".
|
||||
Both are correct: "gone" is the *execution* side (no
|
||||
scheduler entry, no instructions retired), "leaked" is the
|
||||
*memory* side (the dead threads' stacks and per-thread
|
||||
heap structures still ride into the child's address space
|
||||
as orphaned COW pages with no owner and no cleanup hook).
|
||||
Same POSIX reality, two halves of the same coin.
|
||||
|
||||
## The two framings
|
||||
|
||||
[python-trio/trio#1614][trio-1614] (the canonical "trio +
|
||||
fork" hazards thread) puts it this way:
|
||||
|
||||
> If you use `fork()` in a process with multiple threads,
|
||||
> all the other thread stacks are just leaked: there's
|
||||
> nothing else you can reasonably do with them.
|
||||
|
||||
`tractor.spawn._main_thread_forkserver`'s module docstring
|
||||
(specifically the "What survives the fork? — POSIX
|
||||
semantics" section) puts it this way:
|
||||
|
||||
> POSIX `fork()` only preserves the *calling* thread as a
|
||||
> runnable thread in the child. Every other thread in the
|
||||
> parent — trio's runner thread, any `to_thread` cache
|
||||
> threads, anything else — never executes another
|
||||
> instruction post-fork.
|
||||
|
||||
A reader bouncing between the two can be forgiven for
|
||||
asking: well, *which* is it — leaked or gone?
|
||||
|
||||
The answer is "yes". They're describing the same POSIX
|
||||
behavior from two different angles:
|
||||
|
||||
- trio is talking about the **bytes** the dead threads
|
||||
leave behind — stacks, TLS slots, per-thread arena
|
||||
metadata — and the fact that nothing in the child can
|
||||
drive them forward, free them, or even safely walk
|
||||
them. That's a memory leak in the strict sense: held
|
||||
but unreachable.
|
||||
- tractor is talking about the **execution** side
|
||||
relevant to the forkserver design: which threads
|
||||
retire instructions in the child? Exactly one — the
|
||||
one that called `fork()`. Everything else, regardless
|
||||
of the bytes left behind, is dead in a scheduler
|
||||
sense.
|
||||
|
||||
Neither framing is wrong; they're just answering
|
||||
different questions.
|
||||
|
||||
## POSIX `fork()` in a multi-threaded program — what actually happens
|
||||
|
||||
Per POSIX (and concretely on Linux glibc), the contract
|
||||
of `fork()` in a multi-threaded process is:
|
||||
|
||||
1. The kernel creates a new process whose virtual
|
||||
address space is a COW copy of the parent's. *All*
|
||||
pages map across — code, heap, every thread's stack,
|
||||
every malloc arena, every mmap region.
|
||||
2. Of the parent's N threads, exactly **one** is
|
||||
reified in the child as a runnable kernel task: the
|
||||
thread that called `fork()`. The other N-1 threads
|
||||
have *no* corresponding task in the child kernel. They
|
||||
were never scheduled, never `clone()`d for the child,
|
||||
never exist as runnable entities.
|
||||
3. Their **memory artifacts** — pthread stacks, TLS,
|
||||
`pthread_t` structures, glibc per-thread arena
|
||||
bookkeeping — are still mapped in the child's address
|
||||
space, because (1) duplicates *everything* page-wise.
|
||||
They sit there as inert COW bytes.
|
||||
4. The kernel does not clean those bytes up. There is no
|
||||
"phantom-thread cleanup" pass post-fork. The kernel
|
||||
doesn't know which mapped pages "belonged to" which
|
||||
thread — at the kernel level mappings are
|
||||
process-scoped, not thread-scoped.
|
||||
5. The surviving thread (the caller of `fork()`) cannot
|
||||
safely access those leaked bytes either. Any state
|
||||
they encoded — held mutexes, in-flight syscalls,
|
||||
half-updated invariants — is frozen at whatever
|
||||
instant the parent's fork-syscall observed it. Some
|
||||
of those mutexes may even still be locked from the
|
||||
child's POV (the canonical "fork-in-multithreaded-
|
||||
program-deadlocks" hazard; see `man pthread_atfork`).
|
||||
|
||||
So: from the kernel's PoV, the child has one thread.
|
||||
From the address-space's PoV, the child has all the
|
||||
parent's bytes — including the corpses of the N-1 dead
|
||||
threads' stacks. Both true simultaneously.
|
||||
|
||||
## Why trio says "leaked"
|
||||
|
||||
trio's framing makes sense from the parent's
|
||||
PoV, looking at *what those threads were doing*. In a
|
||||
running `trio.run()` process you typically have:
|
||||
|
||||
- The trio runner thread itself — owns the `selectors`
|
||||
epoll fd, the signal-wakeup-fd, the run-queue.
|
||||
- Threadpool worker threads (`trio.to_thread`'s cache)
|
||||
— blocked in `wait()` on the threadpool's work
|
||||
condvar.
|
||||
- Whatever other ad-hoc threads the application
|
||||
started.
|
||||
|
||||
Each of those threads owns *real work-state*: epoll
|
||||
registrations, file descriptors held in
|
||||
soon-to-be-completed reads, half-released locks, posted
|
||||
but unconsumed wakeups. After fork, that state is still
|
||||
encoded in the child's memory. None of it is invalid in
|
||||
a well-formed-bytes sense. It's just that:
|
||||
|
||||
- The thread that was driving it is gone.
|
||||
- Nothing else in the child knows the layout well
|
||||
enough to take over.
|
||||
- Even if it did, the kernel objects backing the work
|
||||
(epoll fd, signalfd) have separate post-fork
|
||||
semantics that don't compose with userland trio
|
||||
state.
|
||||
|
||||
So the bytes are *held* (they're in the child's
|
||||
address space, they count against RSS, they survive
|
||||
until something clobbers them), and they're
|
||||
*unreachable* in any meaningful sense — no thread can
|
||||
safely drive them forward. That is the textbook
|
||||
definition of a leak.
|
||||
|
||||
trio's quote is reminding the user that `fork()` from a
|
||||
multi-threaded process is a one-way memory hazard:
|
||||
whatever those threads were doing, that work-state is
|
||||
now garbage you happen to still be carrying.
|
||||
|
||||
## Why tractor says "gone"
|
||||
|
||||
tractor's `_main_thread_forkserver` framing is concerned
|
||||
with a different question: *which thread executes in the
|
||||
child, and is it safe?*
|
||||
|
||||
The forkserver design rests on POSIX's "calling thread
|
||||
is the sole survivor" guarantee. We pick that calling
|
||||
thread very deliberately: a dedicated worker that has
|
||||
provably never entered trio. So the thread that *does*
|
||||
run in the child is one whose locals, TLS, and stack
|
||||
contain nothing trio-related. Trio's runner thread —
|
||||
the one that owned the epoll fd and the run-queue — is
|
||||
*gone* from the child in the execution sense. It will
|
||||
never run another instruction. The fact that its stack
|
||||
bytes still exist in the child's address space (the
|
||||
"leaked" view) is irrelevant to the forkserver, because
|
||||
nothing in the child reads or writes those pages.
|
||||
|
||||
So when the docstring says "Every other thread … is
|
||||
gone the instant `fork()` returns in the child", it's
|
||||
being precise about the surface that matters for the
|
||||
backend: scheduler-level liveness. Nothing schedules
|
||||
those threads ever again. Whether their bytes are
|
||||
hanging around is a separate (and, for the design,
|
||||
non-load-bearing) fact.
|
||||
|
||||
## Cross-table
|
||||
|
||||
The same tabular layout the `_main_thread_forkserver`
|
||||
docstring uses, expanded with a fourth "what handles
|
||||
it" column:
|
||||
|
||||
| thread | parent | child (executing) | child (memory) | what handles it |
|
||||
|---------------------|-----------|-------------------|------------------------------|-----------------------------|
|
||||
| forkserver worker | continues | sole survivor | live stack | runs the child's bootstrap |
|
||||
| `trio.run()` thread | continues | not running | leaked stack (zombie bytes) | overwritten by child's fresh `trio.run()` |
|
||||
| any other thread | continues | not running | leaked stack (zombie bytes) | overwritten / GC'd / clobbered by `exec()` if used |
|
||||
|
||||
The "child (executing)" column is the *execution* side
|
||||
of the coin — what tractor cares about. The "child
|
||||
(memory)" column is the *memory* side — what trio
|
||||
cares about.
|
||||
|
||||
The "what handles it" column is the deliberate punchline
|
||||
of the design: nothing has to handle the leaked bytes
|
||||
*explicitly*. They get clobbered by ordinary forward
|
||||
progress in the child:
|
||||
|
||||
- The fresh `trio.run()` the child boots up allocates
|
||||
its own stack, scheduler, and run-queue, which over
|
||||
time overlaps and overwrites the inherited zombie
|
||||
pages.
|
||||
- Python's GC walks live objects only; the dead-thread
|
||||
Python frames aren't reachable from any
|
||||
`PyThreadState`, so they get freed at the next
|
||||
collection cycle.
|
||||
- If the child eventually `exec()`s, the entire address
|
||||
space is replaced and the leak vanishes.
|
||||
|
||||
## What this means for the forkserver design
|
||||
|
||||
The crucial point is that **the design doesn't and
|
||||
*can't* prevent the leak**. There is no userland fix
|
||||
for COW thread stacks. The kernel hands the child a
|
||||
duplicated address space; that's what `fork()` *is*. No
|
||||
amount of pre-fork hookery, `pthread_atfork()`
|
||||
gymnastics, or post-fork cleanup can un-COW the dead
|
||||
threads' pages without unmapping them, and unmapping
|
||||
arbitrary regions of a duplicated address space is
|
||||
neither portable nor safe.
|
||||
|
||||
What the design *does* ensure is the orthogonal
|
||||
property: the survivor thread is one that doesn't need
|
||||
any of that leaked state to function. Concretely:
|
||||
|
||||
- Survivor is the forkserver worker thread.
|
||||
- That worker has provably never imported, called into,
|
||||
or held any reference to `trio`. (Enforced by keeping
|
||||
the worker's lifecycle entirely in
|
||||
`_main_thread_forkserver.py` and never letting trio
|
||||
task-state cross into it.)
|
||||
- So the leaked pages — trio runner stack, threadpool
|
||||
caches, etc. — are inert relative to the survivor.
|
||||
No code path in the child references them.
|
||||
- The child then boots its own fresh `trio.run()`,
|
||||
which allocates new state in new pages. Over the
|
||||
child's lifetime the COW'd zombie pages get
|
||||
overwritten, GC'd, or (if the child eventually
|
||||
`exec()`s) discarded wholesale.
|
||||
|
||||
The "leak" is real but inert. It costs RSS until
|
||||
clobbered; it doesn't cost correctness. That's exactly
|
||||
the property the forkserver pattern is built on, and
|
||||
it's also why the design needs the "calling thread is
|
||||
trio-free" precondition to be airtight: if the survivor
|
||||
were a trio thread, it *would* try to drive the leaked
|
||||
trio state, and the leak would no longer be inert.
|
||||
|
||||
## See also
|
||||
|
||||
- `tractor/spawn/_main_thread_forkserver.py` — module
|
||||
docstring's "What survives the fork? — POSIX
|
||||
semantics" section is the in-tree, code-adjacent
|
||||
prose this doc expands on. The cross-table here is a
|
||||
fourth-column expansion of the table there.
|
||||
|
||||
- [python-trio/trio#1614][trio-1614] — the trio issue
|
||||
with the "leaked" framing, and the canonical thread
|
||||
for trio + `fork()` hazards more broadly.
|
||||
|
||||
- [`subint_fork_blocked_by_cpython_post_fork_issue.md`](./subint_fork_blocked_by_cpython_post_fork_issue.md)
|
||||
— sibling analysis covering CPython's *post-fork*
|
||||
hooks (`PyOS_AfterFork_Child`,
|
||||
`_PyInterpreterState_DeleteExceptMain`) and why
|
||||
fork-from-non-main-subint is a CPython-level hard
|
||||
refusal. Complementary axis: this doc is about POSIX
|
||||
semantics; that doc is about the CPython runtime
|
||||
layer that runs *after* POSIX `fork()` returns in
|
||||
the child.
|
||||
|
||||
- `man pthread_atfork(3)` — canonical "fork in a
|
||||
multithreaded process is dangerous" reference.
|
||||
Especially the rationale section, which is the
|
||||
closest thing to a normative statement of "the
|
||||
surviving thread cannot safely use anything the dead
|
||||
threads were touching."
|
||||
|
||||
- `man fork(2)` (Linux) — "Other than [the calling
|
||||
thread], … no other threads are replicated …"
|
||||
paragraph is the kernel-side statement of the
|
||||
execution-side framing this doc opens with.
|
||||
|
||||
[trio-1614]: https://github.com/python-trio/trio/issues/1614
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
# Spawn-time boot-death (`rc=2`) under rapid same-name spawn against a registrar
|
||||
|
||||
## Symptom
|
||||
|
||||
Spawning N (≥4) sub-actors with the **same name** in tight
|
||||
succession against a daemon registrar surfaces as
|
||||
`ActorFailure: Sub-actor (...) died during boot (rc=2)
|
||||
before completing parent-handshake`.
|
||||
|
||||
```
|
||||
tests/discovery/test_multi_program.py
|
||||
::test_dup_name_cancel_cascade_escalates_to_hard_kill[n_dups=4]
|
||||
```
|
||||
|
||||
```
|
||||
tractor._exceptions.ActorFailure:
|
||||
Sub-actor ('doggy', '<uuid>') died during boot (rc=2)
|
||||
before completing parent-handshake.
|
||||
proc: <_ForkedProc pid=<n> returncode=None>
|
||||
```
|
||||
|
||||
The `proc` repr shows `returncode=None` because the repr is
|
||||
captured before `proc.wait()` returns; the actual
|
||||
`os.WEXITSTATUS == 2` is reported via `result['died']` in the
|
||||
race-helper.
|
||||
|
||||
## When it surfaces
|
||||
|
||||
- N=2 (`n_dups=2`): **always passes**.
|
||||
- N=4 (`n_dups=4`): **consistent fail** under both `tpt-proto=tcp`
|
||||
and `tpt-proto=uds`, MTF backend.
|
||||
- N=8 (`n_dups=8`): **passes** (counter-intuitive — see "racing
|
||||
windows").
|
||||
- Non-MTF backends: not yet exercised systematically.
|
||||
|
||||
## What previously masked it
|
||||
|
||||
Pre the spawn-time `wait_for_peer_or_proc_death` race-helper
|
||||
(in `tractor.spawn._spawn`), the parent's `start_actor` flow
|
||||
ended with a bare:
|
||||
|
||||
```python
|
||||
event, chan = await ipc_server.wait_for_peer(uid)
|
||||
```
|
||||
|
||||
That awaits an unsignalled `trio.Event` on `_peer_connected[uid]`.
|
||||
If the sub-actor process **dies during boot** (before its
|
||||
runtime executes the parent-callback handshake that sets the
|
||||
event), the wait parks forever. The dead proc becomes a zombie
|
||||
because no one ever calls `proc.wait()` to reap it.
|
||||
|
||||
In test contexts the failure presented as a hang or a much
|
||||
later `trio.TooSlowError` from an outer `fail_after`. In
|
||||
production it'd present as a parent that never makes progress
|
||||
past `start_actor`. The death itself was silently masked.
|
||||
|
||||
## What surfaces it now
|
||||
|
||||
`tractor.spawn._spawn.wait_for_peer_or_proc_death` (used by
|
||||
`_main_thread_forkserver_proc`) races the handshake-wait
|
||||
against `proc.wait()`. The race-helper raises `ActorFailure`
|
||||
on death-first instead of parking, exposing the rc=2.
|
||||
|
||||
## Hypothesis: registrar-side same-name contention
|
||||
|
||||
The test spawns N actors with name `doggy` sequentially:
|
||||
|
||||
```python
|
||||
for i in range(n_dups):
|
||||
p: Portal = await an.start_actor('doggy')
|
||||
portals.append(p)
|
||||
```
|
||||
|
||||
Each spawned doggy:
|
||||
|
||||
1. Forks via the forkserver.
|
||||
2. Boots its runtime in `_actor_child_main`.
|
||||
3. Connects back to the parent for handshake.
|
||||
4. Connects to the daemon registrar to call `register_actor`.
|
||||
5. Enters its RPC msg-loop.
|
||||
|
||||
Step (4) is where the same-name contention lives. The
|
||||
registrar's `register_actor` (in
|
||||
`tractor.discovery._registry`) accepts duplicate names
|
||||
(stores `(name, uuid) -> addr`), but its internal bookkeeping
|
||||
may have a non-trivial check (e.g. `wait_for_actor` resolution,
|
||||
`_addrs2aids` map updates) that errors out under specific
|
||||
ordering between the existing entry and the incoming one.
|
||||
|
||||
`rc=2 == os.WEXITSTATUS == 2` corresponds to `sys.exit(2)`
|
||||
in the doggy process — typically reached via an unhandled
|
||||
exception that's translated to exit code 2 by Python's top-
|
||||
level (e.g. `argparse` errors use 2; `SystemExit(2)` etc.).
|
||||
So the doggy is hitting an explicit exit path during
|
||||
`register_actor` or just-after.
|
||||
|
||||
The non-monotonic shape (N=2 OK, N=4 BAD, N=8 OK) suggests a
|
||||
specific timing window — likely "the 3rd register-RPC arrives
|
||||
while the 1st-or-2nd is in some intermediate state". With
|
||||
N=8, the additional procs widen the registration spread
|
||||
enough that no two land in the conflicting window.
|
||||
|
||||
## Where to dig next
|
||||
|
||||
- Add per-actor logging in `_actor_child_main` and
|
||||
`register_actor` to surface the actual exception that
|
||||
triggers the rc=2 exit. Currently the doggy dies before
|
||||
the parent ever sees its stderr (forkserver doesn't
|
||||
marshal child stdio back).
|
||||
- Race-test the registrar's `register_actor` /
|
||||
`unregister_actor` / `wait_for_actor` against same-name
|
||||
concurrent calls in isolation (no spawn).
|
||||
- Consider whether `register_actor` should be idempotent
|
||||
under same-name re-register or should explicitly reject
|
||||
same-name (and ideally with a clear `RemoteActorError`,
|
||||
not `sys.exit(2)`).
|
||||
|
||||
## Test-suite handling
|
||||
|
||||
Currently:
|
||||
|
||||
- `tests/discovery/test_multi_program.py
|
||||
::test_dup_name_cancel_cascade_escalates_to_hard_kill[n_dups=4]`
|
||||
is `pytest.mark.xfail(strict=False, reason=...)` to keep
|
||||
the suite green while this issue is investigated.
|
||||
- `n_dups=2` and `n_dups=8` continue to validate the
|
||||
cancel-cascade hard-kill escalation.
|
||||
|
||||
Once the underlying race is understood + fixed, drop the
|
||||
xfail.
|
||||
|
||||
## Related work
|
||||
|
||||
- The cancel-cascade fix that introduced this regression
|
||||
test:
|
||||
`tractor/_exceptions.py:ActorTooSlowError`,
|
||||
`tractor/runtime/_supervise.py:_try_cancel_then_kill`,
|
||||
`tractor/runtime/_portal.py:Portal.cancel_actor(
|
||||
raise_on_timeout=...)`.
|
||||
- The spawn-time death-detection that exposed this:
|
||||
`tractor/spawn/_spawn.py:wait_for_peer_or_proc_death`,
|
||||
used by `tractor/spawn/_main_thread_forkserver.py`.
|
||||
|
|
@ -0,0 +1,273 @@
|
|||
# `test_register_duplicate_name` racy connect-failure on `daemon` fixture readiness
|
||||
|
||||
## Symptom
|
||||
|
||||
`tests/test_multi_program.py::test_register_duplicate_name`
|
||||
fails intermittently under BOTH transports + ALL spawn
|
||||
backends with connect-refused errors:
|
||||
|
||||
```
|
||||
# under --tpt-proto=uds
|
||||
FAILED tests/test_multi_program.py::test_register_duplicate_name
|
||||
- ConnectionRefusedError: [Errno 111] Connection refused
|
||||
( ^^^ this exc was collapsed from a group ^^^ )
|
||||
|
||||
# under --tpt-proto=tcp
|
||||
FAILED tests/test_multi_program.py::test_register_duplicate_name
|
||||
- OSError: all attempts to connect to 127.0.0.1:36003 failed
|
||||
( ^^^ this exc was collapsed from a group ^^^ )
|
||||
```
|
||||
|
||||
Distinct from the cancel-cascade `TooSlowError` flake
|
||||
class — see
|
||||
`cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
This is a **connect-time race** before the daemon is
|
||||
fully ready to `accept()`, not a teardown-cascade
|
||||
slowness.
|
||||
|
||||
## Root cause: blind `time.sleep()` in `daemon` fixture
|
||||
|
||||
`tests/conftest.py::daemon` boots a sub-py-process via
|
||||
`subprocess.Popen([python, '-c', 'tractor.run_daemon(...)'])`,
|
||||
then **blindly sleeps** a fixed delay before yielding
|
||||
`proc` to the test:
|
||||
|
||||
```python
|
||||
# excerpt from tests/conftest.py::daemon
|
||||
proc = subprocess.Popen([
|
||||
sys.executable, '-c', code,
|
||||
])
|
||||
|
||||
bg_daemon_spawn_delay: float = _PROC_SPAWN_WAIT # 0.6
|
||||
if tpt_proto == 'uds':
|
||||
bg_daemon_spawn_delay += 1.6
|
||||
if _non_linux and ci_env:
|
||||
bg_daemon_spawn_delay += 1
|
||||
|
||||
# XXX, allow time for the sub-py-proc to boot up.
|
||||
# !TODO, see ping-polling ideas above!
|
||||
time.sleep(bg_daemon_spawn_delay)
|
||||
|
||||
assert not proc.returncode
|
||||
yield proc
|
||||
```
|
||||
|
||||
Inherent fragility: the delay is "long enough on dev
|
||||
boxes most of the time" but has no actual
|
||||
synchronization with the daemon's `bind()` + `listen()`
|
||||
completion. Under any of:
|
||||
|
||||
- Loaded box (CI parallelism, big rebuild in
|
||||
background, low-cpu-freq)
|
||||
- Cold first-run (`importlib` cache miss, JIT warmup)
|
||||
- Higher-than-expected `tractor` import cost
|
||||
- Filesystem latency (UDS sockfile create, slow
|
||||
tmpfs)
|
||||
|
||||
...the sleep finishes BEFORE the daemon has bound its
|
||||
listen socket → first test client call to
|
||||
`tractor.find_actor()` / `wait_for_actor()` /
|
||||
`open_nursery(registry_addrs=[reg_addr])`'s implicit
|
||||
connect → `ConnectionRefusedError` (TCP) or
|
||||
`FileNotFoundError`/`ConnectionRefusedError` (UDS).
|
||||
|
||||
## Reproducer
|
||||
|
||||
Easiest: run the suite under load.
|
||||
|
||||
```bash
|
||||
# create CPU pressure on another core in parallel
|
||||
stress-ng --cpu 2 --timeout 600s &
|
||||
|
||||
./py313/bin/python -m pytest \
|
||||
tests/test_multi_program.py::test_register_duplicate_name \
|
||||
--spawn-backend=main_thread_forkserver \
|
||||
--tpt-proto=tcp -v
|
||||
```
|
||||
|
||||
Reproduces ~30-50% of the time on a dev laptop. On a
|
||||
quiet idle box, may need 5-10 runs to hit.
|
||||
|
||||
## Why the existing `_PROC_SPAWN_WAIT` tuning is
|
||||
inadequate
|
||||
|
||||
Recent `bg_daemon_spawn_delay` rename
|
||||
(de-monotonic-grow fix) just-shipped removed the
|
||||
*accumulation* bug where each invocation made the
|
||||
NEXT test's wait longer too. Net effect: every
|
||||
invocation now uses the SAME `0.6 + 1.6` (UDS) or
|
||||
`0.6` (TCP) sleep, no growth. Good — but does
|
||||
NOTHING for the underlying race. Each individual
|
||||
test still relies on a blind sleep that may or may
|
||||
not be sufficient.
|
||||
|
||||
Bumping the constant higher pushes flake rate down
|
||||
but never to zero AND adds dead time to every
|
||||
non-flaking run. Not a fix, just a knob.
|
||||
|
||||
## Side effects
|
||||
|
||||
- **Inter-test cascade**: a single failure can cascade
|
||||
via leaked subprocesses (the `daemon` fixture's
|
||||
cleanup may not fully tear down a daemon that never
|
||||
reached "ready"). The `_reap_orphaned_subactors`
|
||||
session-end + `_track_orphaned_uds_per_test`
|
||||
per-test fixtures handle most of this now, but the
|
||||
affected test itself still fails.
|
||||
- **Worsens under fork-spawn backends**: the daemon
|
||||
has more init work
|
||||
(`_main_thread_forkserver`-coordinator-thread
|
||||
startup, etc.) so the sleep has to cover MORE.
|
||||
|
||||
## Fix design — replace blind sleep with active poll
|
||||
|
||||
The right primitive is **poll the daemon's bind
|
||||
address until it accepts a connection or we time
|
||||
out**, with the timeout being a hard ceiling rather
|
||||
than a baseline. Two implementation paths:
|
||||
|
||||
### Path A — TCP/UDS connect-poll loop
|
||||
|
||||
Try `socket.connect(reg_addr)` in a tight loop with
|
||||
short backoff (~50ms), succeed on the first non-error
|
||||
return, fail-loud on a hard cap (e.g. 10s). Same
|
||||
primitive works for both transports because both use
|
||||
`socket.connect()` semantics.
|
||||
|
||||
Rough shape:
|
||||
|
||||
```python
|
||||
def _wait_for_daemon_ready(
|
||||
reg_addr,
|
||||
tpt_proto: str,
|
||||
timeout: float = 10.0,
|
||||
poll_interval: float = 0.05,
|
||||
) -> None:
|
||||
deadline = time.monotonic() + timeout
|
||||
while True:
|
||||
if tpt_proto == 'tcp':
|
||||
sock = socket.socket(socket.AF_INET)
|
||||
target = reg_addr # (host, port)
|
||||
else: # uds
|
||||
sock = socket.socket(socket.AF_UNIX)
|
||||
target = os.path.join(*reg_addr)
|
||||
try:
|
||||
sock.settimeout(poll_interval)
|
||||
sock.connect(target)
|
||||
except (
|
||||
ConnectionRefusedError,
|
||||
FileNotFoundError,
|
||||
socket.timeout,
|
||||
) as exc:
|
||||
if time.monotonic() >= deadline:
|
||||
raise TimeoutError(
|
||||
f'Daemon never accepted on {target!r} '
|
||||
f'within {timeout}s'
|
||||
) from exc
|
||||
time.sleep(poll_interval)
|
||||
else:
|
||||
sock.close()
|
||||
return
|
||||
```
|
||||
|
||||
Pros: trivial primitive, no tractor-runtime
|
||||
dependency, works pre-yield in the fixture body,
|
||||
fail-fast on truly-broken daemon.
|
||||
Cons: doesn't actually do an IPC handshake, just
|
||||
proves listen-side is up. A daemon that bound but
|
||||
hasn't initialized its registrar table yet would
|
||||
still race.
|
||||
|
||||
### Path B — `tractor.find_actor()` poll
|
||||
|
||||
Use the actual discovery API the test would call:
|
||||
|
||||
```python
|
||||
async def _wait_for_daemon_ready_via_discovery(
|
||||
reg_addr,
|
||||
timeout: float = 10.0,
|
||||
poll_interval: float = 0.05,
|
||||
):
|
||||
deadline = trio.current_time() + timeout
|
||||
async with tractor.open_root_actor(
|
||||
registry_addrs=[reg_addr],
|
||||
# ephemeral root just for the probe
|
||||
):
|
||||
while True:
|
||||
try:
|
||||
async with tractor.find_actor(
|
||||
'registrar', # daemon's own name
|
||||
registry_addrs=[reg_addr],
|
||||
) as portal:
|
||||
if portal is not None:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
if trio.current_time() >= deadline:
|
||||
raise TimeoutError(...)
|
||||
await trio.sleep(poll_interval)
|
||||
```
|
||||
|
||||
Pros: actually proves the discovery path works,
|
||||
handles the "bound but not ready" case naturally.
|
||||
Cons: requires booting an ephemeral root actor JUST
|
||||
for the probe (overhead), more code, and runs in trio
|
||||
which complicates the sync-fixture context. Need a
|
||||
`trio.run()` wrapper.
|
||||
|
||||
### Recommended: Path A with optional handshake check
|
||||
|
||||
Path A is much simpler + handles 95% of the bug
|
||||
class. If "bound-but-not-ready" turns out to still
|
||||
race (it shouldn't — `tractor.run_daemon` doesn't
|
||||
return from `bind()` until the registrar is
|
||||
fully populated), escalate to Path B as a focused
|
||||
follow-up.
|
||||
|
||||
## Workarounds (until fix lands)
|
||||
|
||||
1. **Bump `_PROC_SPAWN_WAIT`** higher (current: 0.6).
|
||||
2.0–3.0 hides most flakes at the cost of adding
|
||||
dead time to every test. Not a fix but reduces
|
||||
blast radius while the proper poll lands.
|
||||
2. **`pytest-rerunfailures`** with `reruns=1` on the
|
||||
`daemon` fixture's tests specifically. Hides the
|
||||
flake but doesn't address it.
|
||||
3. **Mark known-affected tests as `xfail(strict=False)`**
|
||||
under `--ci`. Lets CI go green at the cost of
|
||||
silently hiding regressions.
|
||||
|
||||
(Recommend skipping all three — implement the active
|
||||
poll instead.)
|
||||
|
||||
## Investigation next steps
|
||||
|
||||
1. Implement Path A as a `_wait_for_daemon_ready()`
|
||||
helper in `tests/conftest.py`. Replace the
|
||||
`time.sleep(bg_daemon_spawn_delay)` call with it.
|
||||
2. Drop the `_PROC_SPAWN_WAIT` constant entirely
|
||||
(active poll obsoletes blind sleep).
|
||||
3. Run the suite 5-10 times to validate flake rate
|
||||
drops to 0.
|
||||
4. If flakes persist, profile whether the daemon
|
||||
process exits with non-zero before the poll's
|
||||
deadline hits — that'd be a different bug
|
||||
(daemon startup crash) that the blind sleep was
|
||||
masking.
|
||||
5. Cross-check `tests/test_multi_program.py::test_*`
|
||||
— multiple tests use the `daemon` fixture; all
|
||||
should benefit from the same poll primitive.
|
||||
|
||||
## Related
|
||||
|
||||
- `tests/conftest.py::daemon` — the fixture under
|
||||
fix
|
||||
- `tests/conftest.py::_PROC_SPAWN_WAIT` — the
|
||||
constant to drop
|
||||
- `cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`
|
||||
— distinct flake class (cancel-cascade
|
||||
`TooSlowError` at teardown, not connect-time race)
|
||||
- `trio_wakeup_socketpair_busy_loop_under_fork_issue.md`
|
||||
— different bug entirely; this race was masked
|
||||
pre-WakeupSocketpair-patch by the busy-loop
|
||||
hangs.
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
# `trio` 0.29 -> 0.33 slows the depth=3 cancel-cascade
|
||||
|
||||
## Symptom
|
||||
|
||||
After locking to `trio==0.33.0` (commit `c7741bba`, was
|
||||
`0.29.0`), this test reliably trips its `fail_after`
|
||||
deadline on the **`trio`** backend:
|
||||
|
||||
```
|
||||
FAILED tests/test_cancellation.py::test_nested_multierrors[start_method=trio-depth=3]
|
||||
- AssertionError: assert False
|
||||
where False = isinstance(
|
||||
Cancelled(source='deadline', source_task=None, reason=None),
|
||||
tractor.RemoteActorError,
|
||||
)
|
||||
```
|
||||
|
||||
A `fail_after_w_trace` hang-snapshot is captured for the
|
||||
test each run (deadline-injected `Cancelled` wrapped into
|
||||
the actor-nursery `BaseExceptionGroup`).
|
||||
|
||||
## Root cause (immediate)
|
||||
|
||||
The test budgets `fail_after(6)` for the `trio` backend.
|
||||
That 6s was chosen (commit `32955db0`, while `trio==0.29`)
|
||||
with the assertion that trio finishes "well under" 6s.
|
||||
The `trio` 0.29 -> 0.33 bump slowed the depth=3 cascade
|
||||
past that budget, so the 6s deadline now fires mid-cascade.
|
||||
|
||||
trio 0.33 added **cancel-reason tracking** — every
|
||||
`Cancelled` now carries `(source=, reason=, source_task=)`.
|
||||
The injected exc is `Cancelled(source='deadline')`, i.e.
|
||||
trio itself naming our `fail_after(6)` scope as the cancel
|
||||
origin. When that `Cancelled` collapses one branch of the
|
||||
nursery BEG, the test's `isinstance(subexc,
|
||||
RemoteActorError)` assertion fails. The healthy outcome is
|
||||
`BEG = [RemoteActorError, RemoteActorError]`; the
|
||||
`Cancelled` is purely an artifact of the deadline cutting
|
||||
the cascade short.
|
||||
|
||||
## Measurements (standalone, this machine)
|
||||
|
||||
```
|
||||
depth=1 trio ~3.15s PASS (keeps 6s budget)
|
||||
depth=3 trio ~6.8-8.2s FAIL @ 6s (now bumped to 12s)
|
||||
```
|
||||
|
||||
depth=1 still fits comfortably; only depth=3 (deeper
|
||||
recursive spawn-and-error tree => more actors to reap)
|
||||
exceeds the old budget. The ~2s/depth-level cost looks
|
||||
like serialized per-actor reap / `terminate_after` waits.
|
||||
|
||||
## Mitigation applied
|
||||
|
||||
`test_nested_multierrors` now splits the `trio` budget:
|
||||
|
||||
```python
|
||||
case ('trio', 1):
|
||||
timeout = 6
|
||||
case ('trio', 3):
|
||||
timeout = 12 # was 6; see this doc
|
||||
```
|
||||
|
||||
This stops the deadline from firing so the cascade
|
||||
completes naturally to `[RAE, RAE]`.
|
||||
|
||||
## Also affected — same root cause, different test
|
||||
|
||||
`test_echoserver_detailed_mechanics[trio-raise_error=KeyboardInterrupt]`
|
||||
(`tests/test_infected_asyncio.py`) tripped the *same*
|
||||
slowdown via its much tighter `trio` budget of `1s`. The
|
||||
single-aio-subactor teardown now takes ~1s, so the `1s`
|
||||
`fail_after` raced the deadline (PASS at 0.99s / FAIL at
|
||||
1.03s across back-to-back standalone runs). On a deadline-
|
||||
fire the injected `Cancelled(source='deadline')` wraps the
|
||||
mid-stream `KeyboardInterrupt` into a `BaseExceptionGroup`,
|
||||
which is NOT a `KeyboardInterrupt` so the bare
|
||||
`pytest.raises(KeyboardInterrupt)` fails. (The sibling
|
||||
`raise_error=Exception` variant only "passes" by accident:
|
||||
an `ExceptionGroup` *is-a* `Exception`, so its
|
||||
`pytest.raises(Exception)` still matches even when wrapped.)
|
||||
|
||||
Mitigation: bump that `trio` budget `1 -> 4s` (matching the
|
||||
forking-spawner case). Without a deadline-fire the KBI
|
||||
propagates bare and the assertion passes.
|
||||
|
||||
## Open follow-up (the actual regression)
|
||||
|
||||
The budget bump is a band-aid — the underlying question is
|
||||
**why** the depth=3 `trio` cancel-cascade went from <6s to
|
||||
~7-8s across `trio` 0.29 -> 0.33. Candidate avenues:
|
||||
|
||||
- which scope owns the per-actor `terminate_after` wait,
|
||||
and are the tree's reaps concurrent or serialized?
|
||||
- did trio 0.33's abort/reschedule or cancel-reason
|
||||
bookkeeping change checkpoint timing on the cancel path?
|
||||
|
||||
If/when the cascade speeds back up under-budget, depth=3
|
||||
will start completing well under 12s — at which point the
|
||||
budget can be tightened back toward 6s as a regression
|
||||
tripwire. Related (different backend, same cascade class):
|
||||
`cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
|
|
@ -0,0 +1,221 @@
|
|||
# trio `WakeupSocketpair.drain()` busy-loop in forked child (peer-closed missed-EOF)
|
||||
|
||||
## Reproducer
|
||||
|
||||
```bash
|
||||
./py313/bin/python -m pytest \
|
||||
tests/test_multi_program.py::test_register_duplicate_name \
|
||||
--tpt-proto=tcp \
|
||||
--spawn-backend=main_thread_forkserver \
|
||||
-v --capture=sys
|
||||
```
|
||||
|
||||
Subactor pegs a CPU core indefinitely; parent test
|
||||
hangs waiting for the subactor.
|
||||
|
||||
## Empirical evidence (caught alive)
|
||||
|
||||
```
|
||||
$ sudo strace -p <subactor-pid>
|
||||
recvfrom(6, "", 65536, 0, NULL, NULL) = 0
|
||||
recvfrom(6, "", 65536, 0, NULL, NULL) = 0
|
||||
recvfrom(6, "", 65536, 0, NULL, NULL) = 0
|
||||
... (no `epoll_wait`, no other syscalls, just this back-to-back)
|
||||
```
|
||||
|
||||
Pattern: tight C-level `recvfrom` loop returning 0
|
||||
each call. No `epoll_wait` between iterations →
|
||||
**not trio's task scheduler**. Pure synchronous C
|
||||
loop.
|
||||
|
||||
```
|
||||
$ sudo readlink /proc/<subactor-pid>/fd/6
|
||||
socket:[<inode>]
|
||||
|
||||
$ sudo lsof -p <subactor-pid> | grep ' 6u'
|
||||
<cmd> <pid> goodboy 6u unix 0xffff... 0t0 <inode> type=STREAM (CONNECTED)
|
||||
```
|
||||
|
||||
fd=6 is an **AF_UNIX socket** in CONNECTED state.
|
||||
Even though the test uses `--tpt-proto=tcp`, this fd
|
||||
is NOT a tractor IPC channel — it's an internal
|
||||
trio socketpair.
|
||||
|
||||
## Root-cause: `WakeupSocketpair.drain()`
|
||||
|
||||
`/site-packages/trio/_core/_wakeup_socketpair.py`:
|
||||
|
||||
```python
|
||||
class WakeupSocketpair:
|
||||
def __init__(self) -> None:
|
||||
self.wakeup_sock, self.write_sock = socket.socketpair()
|
||||
self.wakeup_sock.setblocking(False)
|
||||
self.write_sock.setblocking(False)
|
||||
...
|
||||
|
||||
def drain(self) -> None:
|
||||
try:
|
||||
while True:
|
||||
self.wakeup_sock.recv(2**16)
|
||||
except BlockingIOError:
|
||||
pass
|
||||
```
|
||||
|
||||
`socket.socketpair()` on Linux defaults to AF_UNIX
|
||||
SOCK_STREAM. Both ends non-blocking. Normal flow:
|
||||
|
||||
1. Signal/wake event → `write_sock.send(b'\x00')`
|
||||
queues a byte.
|
||||
2. `wakeup_sock` becomes readable → trio's epoll
|
||||
triggers.
|
||||
3. Trio calls `drain()` to flush the buffer.
|
||||
4. drain loops on `wakeup_sock.recv(64KB)`.
|
||||
5. Eventually buffer empty → non-blocking socket
|
||||
raises `BlockingIOError` → except → break.
|
||||
|
||||
**Bug surface — peer-closed missed-EOF**:
|
||||
|
||||
Non-blocking socket semantics:
|
||||
- buffer has data → `recv` returns N>0 bytes (loop continues)
|
||||
- buffer empty → `recv` raises `BlockingIOError`
|
||||
- **peer FIN'd → `recv` returns 0 bytes (NEITHER exception NOR
|
||||
break — infinite tight loop)**
|
||||
|
||||
`drain()` does not handle the `b''` return-value
|
||||
(EOF) case. If `write_sock` has been closed (or the
|
||||
process holding it is gone), every iteration returns
|
||||
0 → infinite loop → 100% CPU on a single core.
|
||||
|
||||
## Why this triggers under `main_thread_forkserver`
|
||||
|
||||
Under `os.fork()` from the forkserver-worker thread:
|
||||
|
||||
1. Parent has a `WakeupSocketpair` instance with
|
||||
`wakeup_sock=fdN`, `write_sock=fdM`. Both fds
|
||||
open in parent.
|
||||
2. Fork → child inherits BOTH fds (kernel-level fd
|
||||
table dup).
|
||||
3. `_close_inherited_fds()` runs in child →
|
||||
closes everything except stdio. `wakeup_sock` and
|
||||
`write_sock` of the parent's `WakeupSocketpair`
|
||||
ARE closed in child.
|
||||
4. Child's trio (running fresh) creates its OWN
|
||||
`WakeupSocketpair` → NEW fd numbers (e.g. fd 6, 7).
|
||||
5. **In `infect_asyncio` mode** the asyncio loop is
|
||||
the host; trio runs as guest via
|
||||
`start_guest_run`. trio still creates its
|
||||
`WakeupSocketpair` in the I/O manager but its
|
||||
role is different.
|
||||
|
||||
The race window: somewhere between (3) and (5), if a
|
||||
`WakeupSocketpair` Python object reference inherited
|
||||
via COW (from parent's pre-fork heap) survives long
|
||||
enough that `drain()` is called on it AFTER its fds
|
||||
were closed but BEFORE the child's NEW socketpair
|
||||
takes over the recycled fd numbers — the recycled fd
|
||||
will be one of the child's NEW socketpair ends, whose
|
||||
peer might be FIN-flagged (e.g. parent-process
|
||||
peer-end is closed).
|
||||
|
||||
Or simpler: the `wait_for_actor`/`find_actor` discovery
|
||||
flow in `test_register_duplicate_name` triggers an
|
||||
unusual code path where a stale `WakeupSocketpair`
|
||||
gets `drain()`-called on a fd whose peer has already
|
||||
closed.
|
||||
|
||||
## Why `drain()` shouldn't loop indefinitely on EOF
|
||||
(upstream trio bug)
|
||||
|
||||
Even WITHOUT fork, `drain()` should treat `b''` as
|
||||
EOF and break. The current code is correct for the
|
||||
"buffer drained on a healthy socketpair" scenario but
|
||||
incorrect for the "peer is gone" scenario. It's a
|
||||
defensive-programming gap in trio.
|
||||
|
||||
A one-line patch upstream:
|
||||
|
||||
```python
|
||||
def drain(self) -> None:
|
||||
try:
|
||||
while True:
|
||||
data = self.wakeup_sock.recv(2**16)
|
||||
if not data:
|
||||
break # peer-closed; nothing more to drain
|
||||
except BlockingIOError:
|
||||
pass
|
||||
```
|
||||
|
||||
## Workarounds (until the underlying issue lands)
|
||||
|
||||
1. **Skip-mark on the fork backend**:
|
||||
`tests/test_multi_program.py` →
|
||||
`pytest.mark.skipon_spawn_backend('main_thread_forkserver',
|
||||
reason='trio WakeupSocketpair.drain busy-loop, see ai/conc-anal/trio_wakeup_socketpair_busy_loop_under_fork_issue.md')`.
|
||||
|
||||
2. **Defensive monkey-patch in tractor's
|
||||
forkserver-child prelude** — wrap
|
||||
`WakeupSocketpair.drain` to handle `b''`:
|
||||
|
||||
```python
|
||||
# in `_actor_child_main` or `_close_inherited_fds`'s
|
||||
# post-fork prelude:
|
||||
from trio._core._wakeup_socketpair import WakeupSocketpair
|
||||
_orig_drain = WakeupSocketpair.drain
|
||||
def _safe_drain(self):
|
||||
try:
|
||||
while True:
|
||||
data = self.wakeup_sock.recv(2**16)
|
||||
if not data:
|
||||
return # peer closed
|
||||
except BlockingIOError:
|
||||
pass
|
||||
WakeupSocketpair.drain = _safe_drain
|
||||
```
|
||||
|
||||
Tracks upstream — remove once trio fixes.
|
||||
|
||||
3. **Upstream the fix**: 1-line PR to `python-trio/trio`
|
||||
adding `if not data: break` to `drain()`.
|
||||
|
||||
## Investigation next steps
|
||||
|
||||
1. **Confirm via py-spy**: when caught alive, detach
|
||||
strace first then
|
||||
`sudo py-spy dump --pid <subactor> --locals`. The
|
||||
busy thread should show `drain` from `WakeupSocketpair`
|
||||
in the call chain.
|
||||
2. **Identify which write-end peer is closed**: from
|
||||
the inode of fd 6, look up the matching peer
|
||||
inode via `ss -xp` and see whose process it
|
||||
was/is.
|
||||
3. **Verify the missed-EOF hypothesis**: hand-craft a
|
||||
minimal `WakeupSocketpair` repro:
|
||||
|
||||
```python
|
||||
from trio._core._wakeup_socketpair import WakeupSocketpair
|
||||
ws = WakeupSocketpair()
|
||||
ws.write_sock.close() # simulate peer-gone
|
||||
ws.drain() # should hang forever
|
||||
```
|
||||
|
||||
## Sibling bug
|
||||
|
||||
`tests/test_infected_asyncio.py::test_aio_simple_error`
|
||||
hangs under the same backend with a DIFFERENT
|
||||
fingerprint (Mode-A deadlock, both parties in
|
||||
`epoll_wait`, no busy-loop). Distinct root cause —
|
||||
see `infected_asyncio_under_main_thread_forkserver_hang_issue.md`.
|
||||
|
||||
Both share the broader theme: **trio internal-state
|
||||
initialization isn't fully fork-safe under
|
||||
`main_thread_forkserver`** for the more exotic
|
||||
dispatch paths.
|
||||
|
||||
## See also
|
||||
|
||||
- [#379](https://github.com/goodboy/tractor/issues/379) — subint umbrella
|
||||
- python-trio/trio#1614 — trio + fork hazards
|
||||
- `trio._core._wakeup_socketpair.WakeupSocketpair`
|
||||
source (the smoking gun)
|
||||
- `ai/conc-anal/fork_thread_semantics_execution_vs_memory.md`
|
||||
- `ai/conc-anal/infected_asyncio_under_main_thread_forkserver_hang_issue.md`
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
---
|
||||
model: claude-opus-4-7[1m]
|
||||
service: claude
|
||||
session: trio-0.33-subproc-supervisor-retroactive
|
||||
timestamp: 2026-06-01T23:14:29Z
|
||||
git_ref: 0e3e008b
|
||||
scope: code
|
||||
substantive: true
|
||||
raw_file: 20260601T231429Z_0e3e008b_prompt_io.raw.md
|
||||
---
|
||||
|
||||
## Prompt
|
||||
|
||||
**RETROACTIVE LOG** — original session prompts not
|
||||
preserved; reconstructed from the staged work product.
|
||||
|
||||
The work designs a `trio.Nursery.start()`-style wrapper
|
||||
around `trio.run_process()` for SC-friendly subprocess
|
||||
supervision. From the resulting code shape, the
|
||||
prompting intent was:
|
||||
|
||||
1. Surface rc!=0 `CalledProcessError` DETERMINISTICALLY,
|
||||
without the nursery-eg-wrapping that complicates
|
||||
`collapse_eg()` usage and races the relay reader on
|
||||
trio's `check=True`-driven cancel cascade.
|
||||
2. ALWAYS isolate the parent controlling-tty so a
|
||||
spawned child can't emit terminal control-seqs onto
|
||||
the launching tty (clobbering scrollback). Default
|
||||
`stdin=DEVNULL`; default `stdout=DEVNULL` unless
|
||||
explicitly relayed/overridden; distinguish "caller
|
||||
passed nothing" from "caller passed `None` for
|
||||
inherit".
|
||||
3. Optional live per-line relay of child std-streams to
|
||||
the `tractor` log — STREAMED (not
|
||||
buffered-until-exit) so long-lived daemon output is
|
||||
visible during the run. Pick a custom log level that
|
||||
shows at usual `info`/`devx` console levels but is
|
||||
separately filterable.
|
||||
4. Concurrent pipe-drain reader MANDATORY when piping
|
||||
without `capture_*` — without it the child blocks on
|
||||
`write()` once the OS pipe buffer fills (~64KiB),
|
||||
causing deadlocks on output bursts.
|
||||
5. Non-blocking `tn.start()` semantics: hand the live
|
||||
`trio.Process` to the parent immediately;
|
||||
supervise/relay run to completion in the supervisor
|
||||
coro.
|
||||
6. Hermetic `trio`-only unit tests (no actor-runtime)
|
||||
covering each of: per-line relay, tty isolation,
|
||||
no-deadlock on >64KiB unnewlined output, CPE
|
||||
rebuild w/ stderr relay, CPE rebuild on the silent
|
||||
drain+capture path.
|
||||
|
||||
## Response summary
|
||||
|
||||
Adds `tractor/trionics/_subproc.py` (296 LOC) +
|
||||
`tests/trionics/test_subproc.py` (230 LOC) + a
|
||||
re-export in `tractor/trionics/__init__.py`.
|
||||
|
||||
**`supervise_run_process()`** (public, re-exported)
|
||||
- `check=False` is forced to `trio.run_process`; the
|
||||
rc-check runs in the supervisor coro AFTER `own_tn`
|
||||
unwinds (both the child AND the relay readers have
|
||||
hit EOF + fully drained). A BARE
|
||||
`subprocess.CalledProcessError` is rebuilt + raised
|
||||
from there, with `.stderr` bytes passed in the
|
||||
constructor AND attached as an `add_note()`'d
|
||||
`|_.stderr:` block for legible teardown logs.
|
||||
- `stdin=DEVNULL` always. `stdout` default chosen via a
|
||||
`_UNSET` sentinel: `relay_stdout=True` → PIPE,
|
||||
explicit `stdout=...` → as given, else `DEVNULL`.
|
||||
`stderr` defaults to PIPE whenever we relay OR need
|
||||
the CPE note (when `check=True`), else `DEVNULL`.
|
||||
- `relay_level='io'` (custom level 21; sorts just
|
||||
above stdlib `INFO`=20 so it shows at usual
|
||||
`info`/`devx` levels and stays separately
|
||||
filterable). `runtime`=15 would silently filter at
|
||||
default levels, so it's rejected as a default.
|
||||
- `task_status.started(trio_proc)` delivers the live
|
||||
process immediately. The internal `own_tn`
|
||||
supervises `trio.run_process` + any relay readers to
|
||||
completion.
|
||||
- `**run_process_kwargs` forward verbatim;
|
||||
`stdin/stdout/stderr/check` are MANAGED keys
|
||||
(override on conflict).
|
||||
- Crash-handling deliberately NOT baked in — compose
|
||||
`maybe_open_crash_handler()` on top at the call-site.
|
||||
|
||||
**`_relay_stream_lines()`** (internal helper)
|
||||
- Three modes (combinable): `emit`-only (live per-line
|
||||
relay), `accum`-only (silent drain+capture for a CPE
|
||||
note), or both (live relay AND capture).
|
||||
- Per-line split handles cross-chunk residuals via a
|
||||
rolling `residual` bytes buffer; flushes any trailing
|
||||
un-newline-term'd line at EOF.
|
||||
- `async with stream:` ensures aclose at EOF/cancel
|
||||
(mirrors trio's internal `_subprocess` drain idiom).
|
||||
|
||||
**`_add_stderr_note()`** (internal helper)
|
||||
- `add_note()`s a `textwrap.indent(...)`'d
|
||||
`|_.stderr:` block onto a `CalledProcessError` for
|
||||
teardown logs.
|
||||
|
||||
**Tests** (5 hermetic, trio-only) — `_capture_relay`
|
||||
fixture monkeypatches `_subproc.log.<level>` to a list:
|
||||
- `test_stdout_relayed_per_line`: per-line stdout
|
||||
relay carries each `line=N` to the records.
|
||||
- `test_parent_tty_isolated`: `readlink /proc/self/fd/0`
|
||||
and `fd/1` from the child show `pipe:` (fd1) +
|
||||
`/dev/null` (fd0); NO `/dev/pts/*`.
|
||||
- `test_no_deadlock_on_big_unnewlined_output`: 200KiB
|
||||
of `x` with no newlines completes inside
|
||||
`fail_after(2)` — exercises the concurrent drain.
|
||||
- `test_stderr_relay_and_cpe_rebuild`: rc=3 with
|
||||
`relay_stderr=True` raises bare CPE
|
||||
(via `collapse_eg()`) with `b'boom' in cpe.stderr`,
|
||||
the note attached, AND per-line live relay.
|
||||
- `test_nonrelay_cpe_note`: rc=7 with no relay still
|
||||
produces CPE with `.stderr` + note via the silent
|
||||
drain+capture path.
|
||||
|
||||
## Files changed
|
||||
|
||||
- `tractor/trionics/_subproc.py` — NEW. Public
|
||||
`supervise_run_process()` + helpers
|
||||
`_relay_stream_lines()` / `_add_stderr_note()` + the
|
||||
`_UNSET` sentinel.
|
||||
- `tests/trionics/test_subproc.py` — NEW. 5 hermetic
|
||||
trio-only tests + `_capture_relay` monkeypatch
|
||||
fixture.
|
||||
- `tractor/trionics/__init__.py` — re-export
|
||||
`supervise_run_process`.
|
||||
|
||||
## Human edits
|
||||
|
||||
**RETROACTIVE**: this log is being written from the
|
||||
staged diff, not from a live session. The code as
|
||||
staged is the canonical artifact; any human edits the
|
||||
user made during the originating design session are
|
||||
already integrated and cannot be separated post-hoc.
|
||||
The `.raw.md` sibling is a diff-pointer placeholder,
|
||||
NOT a pre-edit transcript.
|
||||
|
||||
Future prompt-io entries for in-flight work should be
|
||||
written DURING the design session per the skill
|
||||
contract so the pre-edit `.raw.md` captures the
|
||||
unedited model output for genuine provenance.
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
---
|
||||
model: claude-opus-4-7[1m]
|
||||
service: claude
|
||||
timestamp: 2026-06-01T23:14:29Z
|
||||
git_ref: 0e3e008b
|
||||
diff_cmd: git diff HEAD~1..HEAD
|
||||
---
|
||||
|
||||
# RETROACTIVE — original model output not preserved
|
||||
|
||||
This `.raw.md` would normally contain the verbatim
|
||||
pre-human-edit response from the design session that
|
||||
produced the staged `_subproc.py` module + tests. That
|
||||
session's transcript is not available, so this file
|
||||
serves as a diff-pointer placeholder + transparency
|
||||
note.
|
||||
|
||||
## Authoritative artifact
|
||||
|
||||
The committed code IS the artifact of record. Once the
|
||||
companion commit lands, the unified diff is:
|
||||
|
||||
> `git diff HEAD~1..HEAD -- tractor/trionics/_subproc.py`
|
||||
> `git diff HEAD~1..HEAD -- tests/trionics/test_subproc.py`
|
||||
> `git diff HEAD~1..HEAD -- tractor/trionics/__init__.py`
|
||||
|
||||
Before committing, substitute `--cached` for the
|
||||
pre-commit form.
|
||||
|
||||
## What is NOT here
|
||||
|
||||
Because this is retroactive:
|
||||
- No verbatim chain-of-thought / discussion prose from
|
||||
the design session.
|
||||
- No rejected alternatives the model considered before
|
||||
arriving at the final shape (e.g. whether the
|
||||
rc-check should live inside `own_tn` vs after it; the
|
||||
`_UNSET` sentinel vs a `None`-means-DEVNULL
|
||||
convention; `io` vs `info` as the default relay
|
||||
level).
|
||||
- No pre-edit code blocks as the model first emitted
|
||||
them, separable from any user cleanup applied before
|
||||
the diff was staged.
|
||||
|
||||
## Inferred design choices visible in the final code
|
||||
|
||||
(Documented here because they're the kind of decision
|
||||
detail an unedited raw transcript would have captured.)
|
||||
|
||||
1. **Post-drain rc-check in the supervisor coro body,
|
||||
AFTER `own_tn.__aexit__`.** Placing the
|
||||
`CalledProcessError` raise here (not inside
|
||||
`own_tn`) means the EG-unwrap happens at the OUTER
|
||||
`tn.start()` boundary — callers do `collapse_eg()`
|
||||
if they want bare. Doing the raise INSIDE `own_tn`
|
||||
would cancel the still-draining relay reader
|
||||
mid-flight and lose stderr lines.
|
||||
|
||||
2. **`_UNSET` sentinel for `stdout`.** A plain default
|
||||
of `None` couldn't distinguish "use the safe
|
||||
`DEVNULL` default" from "caller explicitly passed
|
||||
`None` (inherit, presumably knowingly)". The
|
||||
sentinel keeps the SAFE default while letting power
|
||||
users opt into inherit.
|
||||
|
||||
3. **`relay_level='io'` (custom level 21).** Chosen to
|
||||
sort just above stdlib `INFO`=20 so a default
|
||||
`--ll info` shows the relay, but it remains a
|
||||
distinct level so users can filter
|
||||
`tractor.trionics:io` separately. Picking
|
||||
`runtime`=15 would have made the relay invisible at
|
||||
default verbosity (a footgun for daemon supervisors
|
||||
whose whole point is "I want to see this output").
|
||||
|
||||
4. **Reader is MANDATORY, not opt-in cosmetic.** With
|
||||
`stdout=PIPE` / `stderr=PIPE` we OWN the drain
|
||||
responsibility — there's no `trio.capture_*` running
|
||||
under the hood here. The ~64KiB OS pipe buffer
|
||||
means a child writing more than that without us
|
||||
reading hangs at `write()` — a deadlock that won't
|
||||
show up in small-output tests, which is why the
|
||||
200KiB-no-newline test is in the suite.
|
||||
|
||||
5. **`task_status.started(trio_proc)` BEFORE the
|
||||
`own_tn` exits.** Without this, `tn.start()` would
|
||||
block until the child exits — losing the "start a
|
||||
long-lived daemon and continue with parent work"
|
||||
use case. With it, the parent gets the live process
|
||||
handle immediately and the supervise+relay tasks
|
||||
run in the supervisor coro until the child exits.
|
||||
|
||||
6. **`__notes__` via `add_note()` for the CPE
|
||||
`.stderr`.** The `.stderr` attribute is what
|
||||
`subprocess` callers expect; the `add_note()` is
|
||||
what trio's exception-rendering shows. Both wired so
|
||||
programmatic AND human consumers see the stderr at
|
||||
teardown.
|
||||
|
||||
## Honesty statement
|
||||
|
||||
This file's content is RECONSTRUCTED from the staged
|
||||
code, not extracted from a verbatim model transcript.
|
||||
The prompt-io skill's intent is for the `.raw.md` to
|
||||
be a pre-edit fossil; that's not possible here. Future
|
||||
work should write the prompt-io entry DURING the
|
||||
design session.
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
# Logging-spec leaf-module granularity — "Route B" (decouple
|
||||
# logger-*identity* from console-*display*)
|
||||
|
||||
Follow-up notes recording the breaking-changes / costs of the
|
||||
deeper fix that would give the `tractor.log` logging-spec (see
|
||||
`LogSpec`/`apply_logspec()`) true **per-leaf-MODULE** level
|
||||
control — deliberately *not* taken (for now) in favour of the
|
||||
smaller sub-PACKAGE fix already landed.
|
||||
|
||||
## Status / what already shipped
|
||||
|
||||
The cheap, contained fix is **done**: `get_logger()`'s "strip
|
||||
#2" (`log.py`, the `pkg_path = subpkg_path` collapse) no longer
|
||||
eats a real sub-package component. It now strips the trailing
|
||||
token *only* when it duplicates the caller's leaf-*module*
|
||||
filename (which the header already shows via `{filename}`).
|
||||
|
||||
Result:
|
||||
|
||||
- `devx.debug` resolves to `tractor.devx.debug`, **distinct**
|
||||
from a bare `devx` -> `tractor.devx` (its parent). So the
|
||||
logging-spec can dial sub-package levels at any nesting depth
|
||||
(`devx.debug:runtime` ≠ `devx:cancel`).
|
||||
- The `get_logger(__name__)` cosmetic ("don't repeat the leaf
|
||||
module in `{name}` since `{filename}` shows it") is preserved.
|
||||
|
||||
What is **still NOT addressable** after that fix:
|
||||
|
||||
- **Per-leaf-MODULE** levels. Every module in a (sub-)pkg shares
|
||||
that pkg's logger, because `get_logger()` drops the leaf
|
||||
module-name from the logger key by design.
|
||||
- **Top-level lib modules** (eg. `tractor.to_asyncio`,
|
||||
`__package__ == 'tractor'`) emit on the *root* `tractor`
|
||||
logger, so a `to_asyncio:<lvl>` spec entry hits a phantom
|
||||
child -> no-op.
|
||||
|
||||
## What "Route B" is
|
||||
|
||||
Make the logger's *identity* the **full dotted module path**
|
||||
(incl. the leaf module + top-level modules), eg.
|
||||
`tractor.devx.debug._tty_lock` and `tractor.to_asyncio`, and
|
||||
move the cosmetic leaf-trim out of logger-naming and into the
|
||||
**formatter's `{name}` rendering**.
|
||||
|
||||
Net effect:
|
||||
|
||||
- Real per-module `Logger` nodes exist in the hierarchy ->
|
||||
the spec can target ANY module; stdlib level-inheritance and
|
||||
propagation "just work" top-down.
|
||||
- Console headers stay clean because the formatter computes a
|
||||
trimmed display string (drop the trailing token that equals
|
||||
`{filename}`'s stem) instead of the logger doing it.
|
||||
|
||||
## Why it's "broad" — breaking changes / costs
|
||||
|
||||
The logger *name* is currently load-bearing well beyond
|
||||
display; changing it ripples:
|
||||
|
||||
1. **Every logger name changes.**
|
||||
Today (post sub-pkg fix) names collapse to the sub-package;
|
||||
Route B = full module path. This touches:
|
||||
- handler attachment points + the `getChild()` hierarchy,
|
||||
- any `logging.getLogger('tractor.X')` string lookups,
|
||||
- any name-based filtering,
|
||||
- the dedup / `_strict_debug` warning logic *inside*
|
||||
`get_logger()` itself — the `pkg_name in name`,
|
||||
`leaf_mod in pkg_path`, "duplicate pkg-name" branches all
|
||||
key off the *name shape* and would need re-derivation.
|
||||
|
||||
2. **Formatter rewrite.**
|
||||
`LOG_FORMAT` uses `{name}` == `record.name` (the full logger
|
||||
name). To keep headers clean we must compute a *display*
|
||||
name and inject it as a record attr (eg. `record.pkg_ns`)
|
||||
via a `logging.Filter` or a `colorlog.ColoredFormatter`
|
||||
subclass overriding `.format()`, then point `LOG_FORMAT` at
|
||||
that field. The `{filename}` vs `{name}` de-dup intent has
|
||||
to be re-implemented per-record rather than per-logger.
|
||||
|
||||
3. **Propagation / double-emit surface grows.**
|
||||
Full-depth loggers mean more intermediate nodes
|
||||
(`...debug._tty_lock` -> `.debug` -> `.devx` -> `tractor`).
|
||||
If more than one level carries a handler (spec sub-handlers
|
||||
+ a root console), records double-emit. The
|
||||
`propagate=False` trick we already use for filter-targeted
|
||||
sub-loggers (`apply_logspec()`) must be applied carefully
|
||||
across a deeper tree — more levels == more places to leak a
|
||||
dup.
|
||||
|
||||
4. **Level-inheritance semantics shift.**
|
||||
Today setting a level on `tractor.devx` gates *all* devx
|
||||
emits (they share that logger). Post-Route-B,
|
||||
`tractor.devx.debug._tty_lock` is its own `NOTSET` logger
|
||||
that *inherits* the effective level from ancestors —
|
||||
functionally similar via inheritance, BUT any code that does
|
||||
`log.setLevel(...)` / reads `log.level` on a (previously
|
||||
collapsed) logger now only affects that exact node. All
|
||||
`setLevel`/`.level =` call sites need an audit (eg.
|
||||
`get_logger()`'s own `log.level = rlog.level` line).
|
||||
|
||||
5. **Downstream contract churn.**
|
||||
`modden` / `piker` call `get_logger()` / `get_console_log()`
|
||||
and may depend on current names — including
|
||||
`modden.runtime.daemon.setup_tractor_logging()` which
|
||||
asserts `'tractor' not in name` on spec parts. The header
|
||||
`{name}` field is user-visible in everyone's logs + CI
|
||||
output. Changing the canonical names is a public-ish
|
||||
behavior change -> needs a version note + downstream
|
||||
coordination (or a formatter trim that keeps the *displayed*
|
||||
string byte-identical to today).
|
||||
|
||||
6. **`get_logger()` refactor risk.**
|
||||
The fn tangles two concerns: compute logger *identity* and
|
||||
compute the *display* string. Route B forces splitting them
|
||||
inside a ~300-line fn with multiple `_strict_debug`
|
||||
branches, dup-warnings, and the `name=__name__` convenience.
|
||||
High chance of subtle regressions without an exhaustive
|
||||
name-derivation test matrix.
|
||||
|
||||
## Migration / test plan (if pursued)
|
||||
|
||||
- Extract a pure helper
|
||||
`_mk_logger_name(pkg_name, mod_name, mod_pkg) -> (logger_name,
|
||||
display_name)` and cover it with an exhaustive unit matrix:
|
||||
auto vs explicit vs `__name__`; package-`__init__` vs leaf
|
||||
module; nested vs flat; `pkg_name in name` vs not; top-level
|
||||
module (`__package__ == pkg_name`).
|
||||
- Switch `get_logger()` to use it for *identity*; switch the
|
||||
formatter to use `display_name` (via a record attr).
|
||||
- Re-run the full suite + golden-diff a sample of rendered log
|
||||
headers to confirm zero cosmetic churn.
|
||||
- Coordinate the name change with `modden`/`piker`; bump +
|
||||
CHANGES note.
|
||||
|
||||
## Cheaper alternative — "Route A" (record-filter)
|
||||
|
||||
If per-leaf control is wanted *before* committing to Route B:
|
||||
keep names collapsed, add a `logging.Filter` on the configured
|
||||
handler keyed on `record.module` / `record.pathname` that maps
|
||||
each record's source module -> its spec level. Set the base
|
||||
logger to the *minimum* level in the spec (so records aren't
|
||||
pre-dropped by the logger), and let the filter discriminate
|
||||
up/down within that floor.
|
||||
|
||||
- Pros: no name churn, no formatter change, fully contained
|
||||
next to `apply_logspec()`.
|
||||
- Cons: a filter can only discriminate *within* what the logger
|
||||
admits -> base must be permissive, so `at_least_level()`
|
||||
expensive-work guards over-admit; matching dotted spec names
|
||||
to a `pathname` is fiddly; doesn't clean up the hierarchy
|
||||
itself.
|
||||
|
||||
## Recommendation
|
||||
|
||||
- Defer Route B unless true per-module loggers are wanted as a
|
||||
first-class feature.
|
||||
- If per-leaf control is needed soon, prefer **Route A**
|
||||
(filter) — lower risk.
|
||||
- The shipped sub-PACKAGE fix already covers the common ask
|
||||
(`devx.debug` vs `devx`).
|
||||
|
|
@ -27,12 +27,9 @@ async def main():
|
|||
'''
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
loglevel='cancel',
|
||||
# loglevel='devx',
|
||||
) as n:
|
||||
|
||||
p0 = await n.start_actor('bp_forever', enable_modules=[__name__])
|
||||
p1 = await n.start_actor('name_error', enable_modules=[__name__])
|
||||
) as an:
|
||||
p0 = await an.start_actor('bp_forever', enable_modules=[__name__])
|
||||
p1 = await an.start_actor('name_error', enable_modules=[__name__])
|
||||
|
||||
# retreive results
|
||||
async with p0.open_stream_from(breakpoint_forever) as stream:
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ async def main():
|
|||
"""
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
# loglevel='cancel',
|
||||
loglevel='pdb',
|
||||
) as n:
|
||||
|
||||
# spawn both actors
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ async def main():
|
|||
'''
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
loglevel='devx',
|
||||
enable_transports=['uds'],
|
||||
enable_transports=['uds'], # TODO, apss this via osenv?
|
||||
loglevel='devx', # XXX, required for test!
|
||||
) as n:
|
||||
|
||||
# spawn both actors
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import trio
|
||||
import tractor
|
||||
|
||||
|
|
@ -9,16 +8,22 @@ async def key_error():
|
|||
|
||||
|
||||
async def main():
|
||||
"""Root dies
|
||||
'''
|
||||
Root is fail-after-cancelled while blocking and child RPC fails
|
||||
simultaneously.
|
||||
|
||||
"""
|
||||
'''
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
loglevel='debug'
|
||||
# loglevel='debug' # ?XXX required?
|
||||
) as n:
|
||||
|
||||
# spawn both actors
|
||||
portal = await n.run_in_actor(key_error)
|
||||
print(
|
||||
f'Child is up @ {portal.chan.aid.reprol()}'
|
||||
)
|
||||
|
||||
|
||||
# XXX: originally a bug caused by this is where root would enter
|
||||
# the debugger and clobber the tty used by the repl even though
|
||||
|
|
|
|||
|
|
@ -49,9 +49,11 @@ async def main(
|
|||
tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
enable_stack_on_sig=True,
|
||||
# maybe_enable_greenback=False,
|
||||
loglevel='devx',
|
||||
loglevel='devx', # XXX REQUIRED log level!
|
||||
enable_transports=[tpt],
|
||||
# maybe_enable_greenback=True,
|
||||
# ^TODO? maybe a "smarter" way todo all this is how
|
||||
# `modden` does with a rtv serialized through the osenv?
|
||||
) as an,
|
||||
):
|
||||
ptl: tractor.Portal = await an.start_actor(
|
||||
|
|
@ -63,7 +65,9 @@ async def main(
|
|||
start_n_shield_hang,
|
||||
) as (ctx, cpid):
|
||||
|
||||
_, proc, _ = an._children[ptl.chan.uid]
|
||||
_, proc, _ = an._children[
|
||||
ptl.chan.aid.uid
|
||||
]
|
||||
assert cpid == proc.pid
|
||||
|
||||
print(
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ async def just_bp(
|
|||
|
||||
async def main():
|
||||
|
||||
# !TODO, parametrize the --tpt-proto={key} with osenv vars just
|
||||
# like we do for loglevel/spawn-backend!
|
||||
# - [ ] run on both tpts for all such debugger tests?
|
||||
# - [ ] special skip for macos!
|
||||
#
|
||||
if platform.system() != 'Darwin':
|
||||
tpt = 'uds'
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ async def name_error():
|
|||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
# loglevel='transport',
|
||||
) as an:
|
||||
|
||||
# TODO: ideally the REPL arrives at this frame in the parent,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
from functools import partial
|
||||
import os
|
||||
import time
|
||||
|
||||
# ?TODO? how to make `pdbp` enforce this?
|
||||
# os.environ['PYTHON_COLORS'] = '0'
|
||||
# os.environ['NO_COLOR'] = '1'
|
||||
|
||||
import trio
|
||||
import tractor
|
||||
|
||||
# disable `pbdp` prompt colors
|
||||
# for prompt matching in test.
|
||||
def disable_pdbp_color():
|
||||
if os.environ.get('PYTHON_COLORS') == '0':
|
||||
from tractor.devx.debug import _repl
|
||||
_repl.TractorConfig.use_pygments = False
|
||||
|
||||
|
||||
# TODO: only import these when not running from test harness?
|
||||
# can we detect `pexpect` usage maybe?
|
||||
# from tractor.devx.debug import (
|
||||
|
|
@ -42,6 +55,7 @@ async def start_n_sync_pause(
|
|||
ctx: tractor.Context,
|
||||
):
|
||||
actor: tractor.Actor = tractor.current_actor()
|
||||
disable_pdbp_color()
|
||||
|
||||
# sync to parent-side task
|
||||
await ctx.started()
|
||||
|
|
@ -52,13 +66,15 @@ async def start_n_sync_pause(
|
|||
|
||||
|
||||
async def main() -> None:
|
||||
disable_pdbp_color()
|
||||
async with (
|
||||
tractor.open_nursery(
|
||||
debug_mode=True,
|
||||
maybe_enable_greenback=True,
|
||||
enable_stack_on_sig=True,
|
||||
# loglevel='warning',
|
||||
# loglevel='devx',
|
||||
|
||||
# XXX flags required for test pattern matching.
|
||||
loglevel='pdb',
|
||||
# enable_stack_on_sig=True,
|
||||
) as an,
|
||||
trio.open_nursery() as tn,
|
||||
):
|
||||
|
|
@ -68,8 +84,8 @@ async def main() -> None:
|
|||
p: tractor.Portal = await an.start_actor(
|
||||
'subactor',
|
||||
enable_modules=[__name__],
|
||||
# infect_asyncio=True,
|
||||
debug_mode=True,
|
||||
# infect_asyncio=True,
|
||||
)
|
||||
|
||||
# TODO: 3 sub-actor usage cases:
|
||||
|
|
|
|||
109
pyproject.toml
109
pyproject.toml
|
|
@ -9,7 +9,7 @@ name = "tractor"
|
|||
version = "0.1.0a6dev0"
|
||||
description = 'structured concurrent `trio`-"actors"'
|
||||
authors = [{ name = "Tyler Goodlet", email = "goodboy_foss@protonmail.com" }]
|
||||
requires-python = ">=3.12, <3.14"
|
||||
requires-python = ">=3.13, <3.15"
|
||||
readme = "docs/README.rst"
|
||||
license = "AGPL-3.0-or-later"
|
||||
keywords = [
|
||||
|
|
@ -29,8 +29,8 @@ classifiers = [
|
|||
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Programming Language :: Python :: 3.14",
|
||||
"Topic :: System :: Distributed Computing",
|
||||
]
|
||||
dependencies = [
|
||||
|
|
@ -46,11 +46,17 @@ dependencies = [
|
|||
# built-in multi-actor `pdb` REPL
|
||||
"pdbp>=1.8.2,<2", # windows only (from `pdbp`)
|
||||
# typed IPC msging
|
||||
"msgspec>=0.21.0",
|
||||
"cffi>=1.17.1",
|
||||
"msgspec>=0.20.0",
|
||||
"bidict>=0.23.1",
|
||||
"multiaddr>=0.2.0",
|
||||
"platformdirs>=4.4.0",
|
||||
# per-actor `argv[0]` proc-title for OS-level diag tools
|
||||
# (`ps`, `top`, `psutil`-backed tooling like `acli.pytree`).
|
||||
# Optional at runtime — guarded by `try/except ImportError` in
|
||||
# `tractor.devx._proctitle` — but listed here so default
|
||||
# installs benefit from it. See tracking issue for follow-ups
|
||||
# (e.g. richer formats, per-backend overrides).
|
||||
"setproctitle>=1.3,<2",
|
||||
]
|
||||
|
||||
# ------ project ------
|
||||
|
|
@ -60,30 +66,58 @@ dev = [
|
|||
{include-group = 'devx'},
|
||||
{include-group = 'testing'},
|
||||
{include-group = 'repl'},
|
||||
{include-group = 'sync_pause'},
|
||||
]
|
||||
devx = [
|
||||
# `tractor.devx` tooling
|
||||
"greenback>=1.2.1,<2",
|
||||
"stackscope>=0.2.2,<0.3",
|
||||
# ^ requires this?
|
||||
"typing-extensions>=4.14.1",
|
||||
# {include-group = 'sync_pause'}, # XXX, no 3.14 yet!
|
||||
]
|
||||
sync_pause = [
|
||||
"greenback>=1.2.1,<2", # TODO? 3.14 greenlet on nix?
|
||||
]
|
||||
testing = [
|
||||
# test suite
|
||||
# TODO: maybe some of these layout choices?
|
||||
# https://docs.pytest.org/en/8.0.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules
|
||||
"pytest>=8.3.5",
|
||||
# bumped 8.3.5 → 9.0.3 per upstream security advisory + our
|
||||
# local-only reliance on the post-9.0 capture-machinery shape
|
||||
# (the `sys.__stderr__`-bypass print in
|
||||
# `tractor._testing.trace._do_capture_snapshot` works on 8.x
|
||||
# too, but standardizing on 9.x here ensures `--show-capture`
|
||||
# interactions stay predictable across dev installs).
|
||||
"pytest>=9.0.3", # CVE-2025-71176 (insecure tmpdir) patched in 9.0.3
|
||||
"pexpect>=4.9.0,<5",
|
||||
# per-test wall-clock bound (used via
|
||||
# `@pytest.mark.timeout(..., method='thread')` on the
|
||||
# known-hanging `subint`-backend audit tests; see
|
||||
# `ai/conc-anal/subint_*_issue.md`).
|
||||
"pytest-timeout>=2.3",
|
||||
# used by `tractor._testing._reap` for the
|
||||
# `tractor-reap` zombie-subactor + leaked-shm
|
||||
# cleanup utility (xplatform `Process.memory_maps`,
|
||||
# `Process.open_files`).
|
||||
"psutil>=7.0.0",
|
||||
]
|
||||
repl = [
|
||||
"pyperclip>=1.9.0",
|
||||
"prompt-toolkit>=3.0.50",
|
||||
"xonsh>=0.22.2",
|
||||
"xonsh>=0.23.8",
|
||||
"psutil>=7.0.0",
|
||||
]
|
||||
lint = [
|
||||
"ruff>=0.9.6"
|
||||
]
|
||||
# XXX, used for linux-only hi perf eventfd+shm channels
|
||||
# now mostly moved over to `hotbaud`.
|
||||
eventfd = [
|
||||
"cffi>=1.17.1",
|
||||
]
|
||||
subints = [
|
||||
"msgspec>=0.21.0",
|
||||
]
|
||||
# TODO, add these with sane versions; were originally in
|
||||
# `requirements-docs.txt`..
|
||||
# docs = [
|
||||
|
|
@ -92,10 +126,26 @@ lint = [
|
|||
# ]
|
||||
# ------ dependency-groups ------
|
||||
|
||||
[tool.uv.dependency-groups]
|
||||
# for subints, we require 3.14+ due to 2 issues,
|
||||
# - hanging behaviour for various multi-task teardown cases (see
|
||||
# "Availability" section in the `tractor.spawn._subints` doc string).
|
||||
# - `msgspec` support which is oustanding per PEP 684 upstream tracker:
|
||||
# https://github.com/jcrist/msgspec/issues/563
|
||||
#
|
||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#group-requires-python
|
||||
subints = {requires-python = ">=3.14"}
|
||||
eventfd = {requires-python = ">=3.13, <3.14"}
|
||||
sync_pause = {requires-python = ">=3.13, <3.14"}
|
||||
|
||||
[tool.uv.sources]
|
||||
# XXX NOTE, only for @goodboy's hacking on `pprint(sort_dicts=False)`
|
||||
# for the `pp` alias..
|
||||
# ------ gh upstream ------
|
||||
# xonsh = { git = 'https://github.com/anki-code/xonsh.git', branch = 'prompt_next_suggestion' }
|
||||
# ^ https://github.com/xonsh/xonsh/pull/6048
|
||||
# xonsh = { git = 'https://github.com/xonsh/xonsh.git', branch = 'main' }
|
||||
# xonsh = { path = "../xonsh", editable = true }
|
||||
|
||||
# [tool.uv.sources.pdbp]
|
||||
# XXX, in case we need to tmp patch again.
|
||||
|
|
@ -164,6 +214,35 @@ all_bullets = true
|
|||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = '6.0'
|
||||
# NOTE: `pytest-timeout`'s global per-test cap is intentionally
|
||||
# NOT set — both of its enforcement methods break trio's
|
||||
# runtime under our fork-based spawn backends:
|
||||
#
|
||||
# - `method='signal'` (the default; SIGALRM) raises `Failed`
|
||||
# synchronously from the signal handler in trio's main
|
||||
# thread, which leaves `GLOBAL_RUN_CONTEXT` half-installed
|
||||
# ("Trio guest run got abandoned"). EVERY subsequent
|
||||
# `trio.run()` in the same pytest session then bails with
|
||||
# `RuntimeError: Attempted to call run() from inside a
|
||||
# run()` — full-session poison: a single 200s hang
|
||||
# cascades into 30+ false-positive failures across
|
||||
# downstream test files.
|
||||
#
|
||||
# - `method='thread'` calls `_thread.interrupt_main()` which
|
||||
# can let the resulting `KeyboardInterrupt` escape trio's
|
||||
# `KIManager` under fork-cascade teardown races, killing
|
||||
# the whole pytest session.
|
||||
#
|
||||
# For tests that legitimately need a wall-clock cap, use
|
||||
# `with trio.fail_after(N):` INSIDE the test — trio's own
|
||||
# Cancelled machinery handles the timeout cleanly through
|
||||
# the actor nursery without disturbing global state. See
|
||||
# `tests/test_advanced_streaming.py::test_dynamic_pub_sub`'s
|
||||
# module-level NOTE for the canonical pattern.
|
||||
#
|
||||
# CI environments should rely on job-level wall-clock
|
||||
# timeouts (e.g. GitHub Actions `timeout-minutes`) for an
|
||||
# escape hatch on genuinely-stuck suites.
|
||||
# https://docs.pytest.org/en/stable/reference/reference.html#configuration-options
|
||||
testpaths = [
|
||||
'tests'
|
||||
|
|
@ -171,15 +250,27 @@ testpaths = [
|
|||
addopts = [
|
||||
# TODO: figure out why this isn't working..
|
||||
'--rootdir=./tests',
|
||||
|
||||
'--import-mode=importlib',
|
||||
# don't show frickin captured logs AGAIN in the report..
|
||||
'--show-capture=no',
|
||||
|
||||
# load builtin plugin since we need a boostrapping hook,
|
||||
# `pytest_load_initial_conftests()` for `--capture=` per:
|
||||
# https://docs.pytest.org/en/stable/reference/reference.html#bootstrapping-hooks
|
||||
'-p tractor._testing.pytest',
|
||||
|
||||
# disable `xonsh` plugin
|
||||
# https://docs.pytest.org/en/stable/how-to/plugins.html#disabling-plugins-from-autoloading
|
||||
# https://docs.pytest.org/en/stable/how-to/plugins.html#deactivating-unregistering-a-plugin-by-name
|
||||
'-p no:xonsh'
|
||||
'-p no:xonsh',
|
||||
|
||||
# XXX default on non-forking spawners
|
||||
'--capture=fd',
|
||||
# '--capture=sys',
|
||||
# ^XXX NOTE^ ALWAYS SET THIS for `*_forkserver` spawner
|
||||
# backends! see details @
|
||||
# `tractor._testing.pytest.pytest_load_initial_conftests()`
|
||||
|
||||
]
|
||||
log_cli = false
|
||||
# TODO: maybe some of these layout choices?
|
||||
|
|
|
|||
|
|
@ -0,0 +1,159 @@
|
|||
#!/usr/bin/env python3
|
||||
# tractor: distributed structured concurrency.
|
||||
# Copyright 2018-eternity Tyler Goodlet.
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
'''
|
||||
`cpu-perf-check` — sustained-load CPU throttle detector.
|
||||
|
||||
Idle freq snapshots LIE. A laptop can read
|
||||
`governor=performance`, `EPP=performance`,
|
||||
`platform_profile=performance`, `scaling_max_freq=<full>`
|
||||
and momentarily clock a P-core at 5GHz — while a
|
||||
firmware/EC power cap (AMD PPT/STAPM and friends) clamps
|
||||
the whole package to ~1.5GHz the instant a sustained
|
||||
multi-core load lands. That throttle masquerades as a
|
||||
`trio`-backend test *regression*: a wave of `fail_after` /
|
||||
`TooSlowError` / `Cancelled(source='deadline')` deadline
|
||||
misses on spawn-heavy tests, on byte-identical code that
|
||||
was green yesterday.
|
||||
|
||||
The existing `tests/conftest.py:cpu_scaling_factor()` only
|
||||
reads STATIC `scaling_max_freq` vs `*_pstate_max_freq`, so
|
||||
it returns `1.0` (no throttle) during exactly this failure
|
||||
— it can't see the cap. This script complements it by
|
||||
BURNING every core for a few seconds and sampling the
|
||||
ACHIEVED `scaling_cur_freq`, which is the only thing that
|
||||
exposes the clamp.
|
||||
|
||||
Exit code: `0` if sustained perf looks restored, `1` if
|
||||
throttled — so it gates a test run:
|
||||
|
||||
py313/bin/python scripts/cpu-perf-check && pytest tests/ ...
|
||||
|
||||
Tunables (env-overridable):
|
||||
CPU_PERF_SECS load duration (default 4.0)
|
||||
CPU_PERF_HEALTHY_FRAC sustained/max floor (default 0.45)
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
import glob
|
||||
import os
|
||||
import time
|
||||
import multiprocessing as mp
|
||||
|
||||
|
||||
def _read(path: str) -> str | None:
|
||||
try:
|
||||
with open(path) as f:
|
||||
return f.read().strip()
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def _cur_freqs_mhz() -> list[int]:
|
||||
out: list[int] = []
|
||||
for f in glob.glob(
|
||||
'/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq'
|
||||
):
|
||||
if (v := _read(f)):
|
||||
out.append(int(v) // 1000)
|
||||
return out
|
||||
|
||||
|
||||
def _pkg_max_mhz() -> int:
|
||||
'''
|
||||
Highest per-core ceiling across the package — the
|
||||
P-core max on hybrid parts.
|
||||
|
||||
'''
|
||||
mxs: list[int] = []
|
||||
for f in glob.glob(
|
||||
'/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq'
|
||||
):
|
||||
if (v := _read(f)):
|
||||
mxs.append(int(v) // 1000)
|
||||
return max(mxs) if mxs else 0
|
||||
|
||||
|
||||
def _burn(stop: float) -> None:
|
||||
x: int = 1
|
||||
while time.perf_counter() < stop:
|
||||
x += x * x ^ 0x5
|
||||
|
||||
|
||||
def main(
|
||||
secs: float = float(os.environ.get('CPU_PERF_SECS', 4.0)),
|
||||
# sustained aggregate must clear this fraction of the
|
||||
# package max-freq ceiling. Throttled (~1.5GHz of 5.1GHz)
|
||||
# ~= 0.29; a healthy all-core load easily clears 0.5.
|
||||
healthy_frac: float = float(
|
||||
os.environ.get('CPU_PERF_HEALTHY_FRAC', 0.45)
|
||||
),
|
||||
) -> int:
|
||||
if not glob.glob('/sys/devices/system/cpu/cpu0/cpufreq'):
|
||||
print('no cpufreq sysfs (non-linux?) — skipping, assume OK')
|
||||
return 0
|
||||
|
||||
b: str = '/sys/devices/system/cpu/cpu0/cpufreq/'
|
||||
pkg_max: int = _pkg_max_mhz()
|
||||
print('=== static knobs (ALL can read fine while throttled) ===')
|
||||
print(f' governor : {_read(b + "scaling_governor")}')
|
||||
print(f' EPP : {_read(b + "energy_performance_preference")}')
|
||||
print(f' platform_profile : '
|
||||
f'{_read("/sys/firmware/acpi/platform_profile")}')
|
||||
print(f' pkg max freq : {pkg_max} MHz')
|
||||
|
||||
ncpu: int = os.cpu_count() or 1
|
||||
print(f'\n=== sustained {ncpu}-core load ({secs:.0f}s) — the real test ===')
|
||||
stop: float = time.perf_counter() + secs
|
||||
procs = [
|
||||
mp.Process(target=_burn, args=(stop,))
|
||||
for _ in range(ncpu)
|
||||
]
|
||||
for p in procs:
|
||||
p.start()
|
||||
|
||||
# skip the initial ~0.6s ramp, then sample steady-state
|
||||
samples: list[int] = []
|
||||
time.sleep(0.6)
|
||||
while time.perf_counter() < stop - 0.2:
|
||||
if (fr := _cur_freqs_mhz()):
|
||||
samples.append(sum(fr) // len(fr))
|
||||
time.sleep(0.3)
|
||||
for p in procs:
|
||||
p.join()
|
||||
|
||||
if not (samples and pkg_max):
|
||||
print(' could not sample cur freq — assume OK')
|
||||
return 0
|
||||
|
||||
sustained: int = sum(samples) // len(samples)
|
||||
frac: float = sustained / pkg_max
|
||||
print(f' aggregate cur-freq samples: {samples}')
|
||||
print(f' sustained avg : {sustained} MHz '
|
||||
f'({frac * 100:.0f}% of {pkg_max} MHz max)')
|
||||
|
||||
if frac < healthy_frac:
|
||||
print(
|
||||
f'\n ❌ THROTTLED — sustained {sustained}MHz is only '
|
||||
f'{frac * 100:.0f}% of max (< {healthy_frac * 100:.0f}%).\n'
|
||||
f' Power cap (PPT/STAPM) still engaged. Fixes:\n'
|
||||
f' - bounce /sys/firmware/acpi/platform_profile\n'
|
||||
f' (balanced -> performance)\n'
|
||||
f' - unplug/replug USB-C to re-negotiate PD\n'
|
||||
f' - ryzenadj to lift STAPM/PPT\n'
|
||||
f' - else reboot\n'
|
||||
f' Do NOT bump test budgets — the box is slow, not the code.'
|
||||
)
|
||||
return 1
|
||||
|
||||
print(
|
||||
f'\n ✅ PERF OK — sustained {sustained}MHz holds '
|
||||
f'{frac * 100:.0f}% of max. Cap looks lifted; safe to run tests.'
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
#!/usr/bin/env python3
|
||||
# tractor: structured concurrent "actors".
|
||||
# Copyright 2018-eternity Tyler Goodlet.
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
'''
|
||||
`tractor-reap` — SC-polite zombie-subactor reaper +
|
||||
optional `/dev/shm/` orphan-segment sweep.
|
||||
|
||||
Two cleanup phases (run in order when both are enabled):
|
||||
|
||||
1. **process reap** — finds `tractor` subactor processes
|
||||
left alive after a `pytest` (or any tractor-app) run
|
||||
that failed to fully cancel its actor tree, then sends
|
||||
SIGINT with a bounded grace window before escalating
|
||||
to SIGKILL.
|
||||
|
||||
2. **shm sweep** (`--shm` / `--shm-only`) — unlinks
|
||||
`/dev/shm/<file>` entries owned by the current uid
|
||||
that no live process has open (mmap'd or fd-held).
|
||||
Needed because `tractor` disables
|
||||
`mp.resource_tracker` (see `tractor.ipc._mp_bs`), so a
|
||||
hard-crashing actor leaves leaked segments that
|
||||
nothing else GCs.
|
||||
|
||||
3. **UDS sweep** (`--uds` / `--uds-only`) — unlinks
|
||||
`${XDG_RUNTIME_DIR}/tractor/<name>@<pid>.sock` files
|
||||
whose binder pid is dead (or the `1616` registry
|
||||
sentinel). Needed because the IPC server's
|
||||
`os.unlink()` cleanup lives in a `finally:` block
|
||||
that doesn't always run on hard exits (SIGKILL,
|
||||
escaped `KeyboardInterrupt`, etc.) — see issue #452.
|
||||
|
||||
Process-reap detection modes (auto-selected):
|
||||
|
||||
--parent <pid> : descendant-mode — kill procs whose
|
||||
PPid == <pid>. Use when a parent
|
||||
is still alive and you want to
|
||||
scope the sweep precisely (e.g.
|
||||
CI wrapper calling in from outside
|
||||
pytest).
|
||||
|
||||
(default) : orphan-mode — kill procs with
|
||||
PPid==1 (init-reparented) whose
|
||||
cwd matches the repo root AND
|
||||
whose cmdline contains `python`.
|
||||
The cwd filter is what prevents
|
||||
sweeping unrelated init-children.
|
||||
|
||||
Usage:
|
||||
|
||||
# process reap only (default)
|
||||
scripts/tractor-reap
|
||||
|
||||
# process reap + shm sweep
|
||||
scripts/tractor-reap --shm
|
||||
|
||||
# only the shm sweep, skip process reap
|
||||
scripts/tractor-reap --shm-only
|
||||
|
||||
# process reap + shm + UDS sweep (the works)
|
||||
scripts/tractor-reap --shm --uds
|
||||
|
||||
# only UDS sweep
|
||||
scripts/tractor-reap --uds-only
|
||||
|
||||
# from inside a still-live supervisor
|
||||
scripts/tractor-reap --parent 12345
|
||||
|
||||
# dry-run: list what would be reaped, don't act
|
||||
scripts/tractor-reap -n
|
||||
scripts/tractor-reap --shm --uds -n
|
||||
|
||||
'''
|
||||
import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def _repo_root() -> pathlib.Path:
|
||||
'''
|
||||
Use `git rev-parse --show-toplevel` when available;
|
||||
fall back to the repo this script lives in.
|
||||
|
||||
'''
|
||||
try:
|
||||
out: str = subprocess.check_output(
|
||||
['git', 'rev-parse', '--show-toplevel'],
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
).strip()
|
||||
return pathlib.Path(out)
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
return pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tractor-reap',
|
||||
description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--parent', '-p',
|
||||
type=int,
|
||||
default=None,
|
||||
help='descendant-mode: reap procs with PPid==<pid>',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--grace', '-g',
|
||||
type=float,
|
||||
default=3.0,
|
||||
help='SIGINT grace window in seconds (default 3.0)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dry-run', '-n',
|
||||
action='store_true',
|
||||
help='list matched pids/paths but do not signal/unlink',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--shm',
|
||||
action='store_true',
|
||||
help=(
|
||||
'after process reap, also unlink orphaned '
|
||||
'/dev/shm segments owned by the current user '
|
||||
'that no live process is mapping or holding open'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--shm-only',
|
||||
action='store_true',
|
||||
help='skip process reap; only do the shm sweep',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--uds',
|
||||
action='store_true',
|
||||
help=(
|
||||
'after process reap, also unlink orphaned '
|
||||
'${XDG_RUNTIME_DIR}/tractor/*.sock files '
|
||||
'whose binder pid is dead (or the 1616 '
|
||||
'registry sentinel). See issue #452.'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--uds-only',
|
||||
action='store_true',
|
||||
help='skip process reap + shm; only do the UDS sweep',
|
||||
)
|
||||
args = parser.parse_args()
|
||||
# any *-only flag also skips the process reap phase
|
||||
skip_proc_reap: bool = (
|
||||
args.shm_only
|
||||
or
|
||||
args.uds_only
|
||||
)
|
||||
|
||||
# import lazily so `--help` doesn't require the tractor
|
||||
# package to be importable (e.g. when running from a
|
||||
# shell not inside a venv).
|
||||
repo = _repo_root()
|
||||
sys.path.insert(0, str(repo))
|
||||
from tractor._testing._reap import (
|
||||
find_descendants,
|
||||
find_orphans,
|
||||
find_orphaned_shm,
|
||||
find_orphaned_uds,
|
||||
reap,
|
||||
reap_shm,
|
||||
reap_uds,
|
||||
)
|
||||
|
||||
rc: int = 0
|
||||
|
||||
# --- phase 1: process reap (skipped under --*-only) ---
|
||||
if not skip_proc_reap:
|
||||
if args.parent is not None:
|
||||
pids: list[int] = find_descendants(args.parent)
|
||||
mode: str = f'descendants of PPid={args.parent}'
|
||||
else:
|
||||
pids = find_orphans(repo)
|
||||
mode = f'orphans (PPid=1, cwd={repo})'
|
||||
|
||||
if not pids:
|
||||
print(f'[tractor-reap] no {mode} to reap')
|
||||
elif args.dry_run:
|
||||
print(
|
||||
f'[tractor-reap] dry-run — {mode}:\n {pids}'
|
||||
)
|
||||
else:
|
||||
_, survivors = reap(pids, grace=args.grace)
|
||||
if survivors:
|
||||
rc = 1
|
||||
|
||||
# --- phase 2: shm sweep (opt-in) ---
|
||||
if args.shm or args.shm_only:
|
||||
leaked: list[str] = find_orphaned_shm()
|
||||
if not leaked:
|
||||
print(
|
||||
'[tractor-reap] no orphaned /dev/shm '
|
||||
'segments to sweep'
|
||||
)
|
||||
elif args.dry_run:
|
||||
print(
|
||||
f'[tractor-reap] dry-run — {len(leaked)} '
|
||||
f'orphaned shm segment(s):\n {leaked}'
|
||||
)
|
||||
else:
|
||||
_, errors = reap_shm(leaked)
|
||||
if errors:
|
||||
rc = 1
|
||||
|
||||
# --- phase 3: UDS sweep (opt-in) ---
|
||||
if args.uds or args.uds_only:
|
||||
leaked_uds: list[str] = find_orphaned_uds()
|
||||
if not leaked_uds:
|
||||
print(
|
||||
'[tractor-reap] no orphaned UDS sock-files '
|
||||
'to sweep'
|
||||
)
|
||||
elif args.dry_run:
|
||||
print(
|
||||
f'[tractor-reap] dry-run — {len(leaked_uds)} '
|
||||
f'orphaned UDS sock-file(s):\n {leaked_uds}'
|
||||
)
|
||||
else:
|
||||
_, errors = reap_uds(leaked_uds)
|
||||
if errors:
|
||||
rc = 1
|
||||
|
||||
# exit 0 if everything cleaned cleanly, else 1 — useful
|
||||
# for CI health-check chaining.
|
||||
return rc
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
|
|
@ -22,7 +22,8 @@ from tractor._testing import (
|
|||
|
||||
pytest_plugins: list[str] = [
|
||||
'pytester',
|
||||
'tractor._testing.pytest',
|
||||
# NOTE, now loaded in `pytest-ini` section of `pyproject.toml`
|
||||
# 'tractor._testing.pytest',
|
||||
]
|
||||
|
||||
_ci_env: bool = os.environ.get('CI', False)
|
||||
|
|
@ -33,15 +34,10 @@ if platform.system() == 'Windows':
|
|||
_KILL_SIGNAL = signal.CTRL_BREAK_EVENT
|
||||
_INT_SIGNAL = signal.CTRL_C_EVENT
|
||||
_INT_RETURN_CODE = 3221225786
|
||||
_PROC_SPAWN_WAIT = 2
|
||||
else:
|
||||
_KILL_SIGNAL = signal.SIGKILL
|
||||
_INT_SIGNAL = signal.SIGINT
|
||||
_INT_RETURN_CODE = 1 if sys.version_info < (3, 8) else -signal.SIGINT.value
|
||||
_PROC_SPAWN_WAIT = (
|
||||
2 if _ci_env
|
||||
else 1
|
||||
)
|
||||
|
||||
|
||||
no_windows = pytest.mark.skipif(
|
||||
|
|
@ -100,91 +96,184 @@ def cpu_scaling_factor() -> float:
|
|||
much to inflate time-limits when CPU-freq scaling is active on
|
||||
linux.
|
||||
|
||||
When no scaling info is available (non-linux, missing sysfs),
|
||||
returns 1.0 (i.e. no headroom adjustment needed).
|
||||
When no local scaling info is available (non-linux, missing
|
||||
sysfs) the base factor is 1.0; a flat CI bump is then applied
|
||||
on top (see below).
|
||||
|
||||
'''
|
||||
factor: float = 1.
|
||||
if not _non_linux:
|
||||
mx = get_cpu_state()
|
||||
cur = get_cpu_state(setting='scaling_max_freq')
|
||||
if (
|
||||
mx is not None
|
||||
and
|
||||
cur is not None
|
||||
):
|
||||
_mx_pth, max_freq = mx
|
||||
_cur_pth, cur_freq = cur
|
||||
cpu_scaled: float = int(cur_freq) / int(max_freq)
|
||||
if cpu_scaled != 1.:
|
||||
factor = 1. / (
|
||||
cpu_scaled * 2 # <- bc likely "dual threaded"
|
||||
)
|
||||
|
||||
# XXX, GH Actions (and most shared) CI runners are slow + noisy
|
||||
# and — unlike a throttled local box — do NOT expose CPU-freq
|
||||
# scaling via sysfs, so the probe above reads 1.0 and adds no
|
||||
# headroom. Apply a flat CI bump so every timing-test deadline
|
||||
# /assert that keys off this factor gets headroom on CI HW
|
||||
# (compounds with any local-throttle factor).
|
||||
#
|
||||
# macOS runners are noticeably slower + noisier than the linux
|
||||
# ones for our multi-actor cancel-cascade tests, so give them
|
||||
# extra headroom (3x vs 2x).
|
||||
if _ci_env:
|
||||
factor *= 3 if _non_linux else 2
|
||||
|
||||
return factor
|
||||
|
||||
|
||||
# session-cached sustained-load throttle multiplier — measured
|
||||
# once (lazily) on the first `cpu_perf_headroom()` call. `None`
|
||||
# = not-yet-measured.
|
||||
_sustained_headroom: float|None = None
|
||||
|
||||
|
||||
def _measure_sustained_headroom(
|
||||
secs: float = 0.9,
|
||||
# a healthy all-core sustained clock holds AT/ABOVE this
|
||||
# fraction of the package single-core max ceiling (boost sags
|
||||
# under full multi-core load even un-throttled, but not far);
|
||||
# at/above it we assume no throttle and return 1.0.
|
||||
throttle_gate: float = 0.6,
|
||||
max_headroom: float = 4.,
|
||||
) -> float:
|
||||
'''
|
||||
One-shot all-core burn returning a latency multiplier
|
||||
(>= 1.0) that reflects *sustained-load* CPU throttle.
|
||||
|
||||
Catches the firmware/EC power-cap clamp (AMD PPT/STAPM &
|
||||
friends) that pins achieved `scaling_cur_freq` to a fraction
|
||||
of the ceiling under multi-core load while EVERY static knob
|
||||
(`governor`, `scaling_max_freq`, `EPP`, `platform_profile`)
|
||||
still reads "full performance". That cap is INVISIBLE to
|
||||
`cpu_scaling_factor()` and is the gremlin behind mass `trio`
|
||||
deadline-miss failures on byte-identical code — see
|
||||
`scripts/cpu-perf-check`.
|
||||
|
||||
Best-effort: returns 1.0 on non-linux / missing sysfs / any
|
||||
error so it can never break a test run.
|
||||
|
||||
'''
|
||||
import glob
|
||||
import multiprocessing as mp
|
||||
|
||||
def _read_mhz(path: str) -> int|None:
|
||||
try:
|
||||
return int(open(path).read()) // 1000
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
try:
|
||||
maxs: list[int] = [
|
||||
v for f in glob.glob(
|
||||
'/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq'
|
||||
)
|
||||
if (v := _read_mhz(f)) is not None
|
||||
]
|
||||
pkg_max: int = max(maxs) if maxs else 0
|
||||
if not pkg_max:
|
||||
return 1.
|
||||
|
||||
def _burn(stop: float) -> None:
|
||||
x: int = 1
|
||||
while time.perf_counter() < stop:
|
||||
x += x * x ^ 0x5
|
||||
|
||||
# explicit `fork` ctx so we're immune to whatever global
|
||||
# mp start-method tractor/the suite may have set (`spawn`
|
||||
# would re-exec + re-import 24x — slow and pointless here).
|
||||
ctx = mp.get_context('fork')
|
||||
ncpu: int = os.cpu_count() or 1
|
||||
stop: float = time.perf_counter() + secs
|
||||
procs = [
|
||||
ctx.Process(target=_burn, args=(stop,), daemon=True)
|
||||
for _ in range(ncpu)
|
||||
]
|
||||
for p in procs:
|
||||
p.start()
|
||||
|
||||
# skip the ~0.4s boost window so we sample the steady
|
||||
# state AFTER any power-cap has engaged.
|
||||
samples: list[int] = []
|
||||
time.sleep(0.4)
|
||||
while time.perf_counter() < stop - 0.1:
|
||||
curs: list[int] = [
|
||||
v for f in glob.glob(
|
||||
'/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq'
|
||||
)
|
||||
if (v := _read_mhz(f)) is not None
|
||||
]
|
||||
if curs:
|
||||
samples.append(sum(curs) // len(curs))
|
||||
time.sleep(0.15)
|
||||
for p in procs:
|
||||
p.join()
|
||||
|
||||
if not samples:
|
||||
return 1.
|
||||
frac: float = (sum(samples) // len(samples)) / pkg_max
|
||||
# below the gate we read it as a power-cap throttle. The
|
||||
# spawn/IPC/fork-bound work these budgets guard slows ~1:1
|
||||
# with the achieved-vs-max freq ratio, so compensate by the
|
||||
# FULL inverse fraction (a boost-discounted factor
|
||||
# under-shoots and still trips the marginal cases).
|
||||
if frac >= throttle_gate:
|
||||
return 1.
|
||||
return min(max_headroom, 1. / frac)
|
||||
|
||||
except Exception:
|
||||
return 1.
|
||||
|
||||
|
||||
def cpu_perf_headroom() -> float:
|
||||
'''
|
||||
Latency-headroom multiplier (>= 1.0) covering BOTH cpu-perf
|
||||
throttle classes — multiply a test's deadline by it, e.g.
|
||||
`timeout *= cpu_perf_headroom()`:
|
||||
|
||||
- static cpu-freq scaling — via `cpu_scaling_factor()`
|
||||
(governor/policy lowered the `scaling_max_freq` ceiling).
|
||||
|
||||
- sustained-load power-cap throttle — via
|
||||
`_measure_sustained_headroom()` (firmware/EC PPT/STAPM
|
||||
clamps achieved freq under load while every static knob
|
||||
reads "performance"; INVISIBLE to the static check). This
|
||||
is the gremlin behind mass `trio` deadline-miss failures
|
||||
on unchanged code — see
|
||||
`ai/conc-anal/trio_033_cancel_cascade_slowdown_depth3_issue.md`.
|
||||
|
||||
The sustained probe runs ONCE per session (cached); the cost
|
||||
is a ~0.9s all-core burn on first call only.
|
||||
|
||||
'''
|
||||
global _sustained_headroom
|
||||
static: float = cpu_scaling_factor()
|
||||
if _non_linux:
|
||||
return 1.
|
||||
|
||||
mx = get_cpu_state()
|
||||
cur = get_cpu_state(setting='scaling_max_freq')
|
||||
if mx is None or cur is None:
|
||||
return 1.
|
||||
|
||||
_mx_pth, max_freq = mx
|
||||
_cur_pth, cur_freq = cur
|
||||
cpu_scaled: float = int(cur_freq) / int(max_freq)
|
||||
|
||||
if cpu_scaled != 1.:
|
||||
return 1. / (
|
||||
cpu_scaled * 2 # <- bc likely "dual threaded"
|
||||
)
|
||||
|
||||
return 1.
|
||||
return static
|
||||
if _sustained_headroom is None:
|
||||
_sustained_headroom = _measure_sustained_headroom()
|
||||
return max(static, _sustained_headroom)
|
||||
|
||||
|
||||
def pytest_addoption(
|
||||
parser: pytest.Parser,
|
||||
):
|
||||
# ?TODO? should this be exposed from our `._testing.pytest`
|
||||
# plugin or should we make it more explicit with `--tl` for
|
||||
# tractor logging like we do in other client projects?
|
||||
parser.addoption(
|
||||
"--ll",
|
||||
action="store",
|
||||
dest='loglevel',
|
||||
default='ERROR', help="logging level to set when testing"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session', autouse=True)
|
||||
def loglevel(request) -> str:
|
||||
import tractor
|
||||
orig = tractor.log._default_loglevel
|
||||
level = tractor.log._default_loglevel = request.config.option.loglevel
|
||||
log = tractor.log.get_console_log(
|
||||
level=level,
|
||||
name='tractor', # <- enable root logger
|
||||
)
|
||||
log.info(
|
||||
f'Test-harness set runtime loglevel: {level!r}\n'
|
||||
)
|
||||
yield level
|
||||
tractor.log._default_loglevel = orig
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def test_log(
|
||||
request,
|
||||
loglevel: str,
|
||||
) -> tractor.log.StackLevelAdapter:
|
||||
'''
|
||||
Deliver a per test-module-fn logger instance for reporting from
|
||||
within actual test bodies/fixtures.
|
||||
|
||||
For example this can be handy to report certain error cases from
|
||||
exception handlers using `test_log.exception()`.
|
||||
|
||||
'''
|
||||
modname: str = request.function.__module__
|
||||
log = tractor.log.get_logger(
|
||||
name=modname, # <- enable root logger
|
||||
# pkg_name='tests',
|
||||
)
|
||||
_log = tractor.log.get_console_log(
|
||||
level=loglevel,
|
||||
logger=log,
|
||||
name=modname,
|
||||
# pkg_name='tests',
|
||||
)
|
||||
_log.debug(
|
||||
f'In-test-logging requested\n'
|
||||
f'test_log.name: {log.name!r}\n'
|
||||
f'level: {loglevel!r}\n'
|
||||
|
||||
)
|
||||
yield _log
|
||||
# NOTE, the `--ll`/`--tl` CLI flags + the `loglevel`, `test_log`
|
||||
# and `testing_pkg_name` fixtures have been factored into the
|
||||
# `tractor._testing.pytest` plugin (loaded via the `-p` entry in
|
||||
# `pyproject.toml`'s `[tool.pytest.ini_options]`) so downstream
|
||||
# consuming projects (eg. `modden`) inherit them for free. The
|
||||
# plugin's `testing_pkg_name` fixture defaults to `'tractor'`, so
|
||||
# this suite keeps treating `--ll` as the runtime loglevel.
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
|
|
@ -236,107 +325,14 @@ def sig_prog(
|
|||
assert ret
|
||||
|
||||
|
||||
# TODO: factor into @cm and move to `._testing`?
|
||||
@pytest.fixture
|
||||
def daemon(
|
||||
debug_mode: bool,
|
||||
loglevel: str,
|
||||
testdir: pytest.Pytester,
|
||||
reg_addr: tuple[str, int],
|
||||
tpt_proto: str,
|
||||
ci_env: bool,
|
||||
test_log: tractor.log.StackLevelAdapter,
|
||||
|
||||
) -> subprocess.Popen:
|
||||
'''
|
||||
Run a daemon root actor as a separate actor-process tree and
|
||||
"remote registrar" for discovery-protocol related tests.
|
||||
|
||||
'''
|
||||
if loglevel in ('trace', 'debug'):
|
||||
# XXX: too much logging will lock up the subproc (smh)
|
||||
loglevel: str = 'info'
|
||||
|
||||
code: str = (
|
||||
"import tractor; "
|
||||
"tractor.run_daemon([], "
|
||||
"registry_addrs={reg_addrs}, "
|
||||
"enable_transports={enable_tpts}, "
|
||||
"debug_mode={debug_mode}, "
|
||||
"loglevel={ll})"
|
||||
).format(
|
||||
reg_addrs=str([reg_addr]),
|
||||
enable_tpts=str([tpt_proto]),
|
||||
ll="'{}'".format(loglevel) if loglevel else None,
|
||||
debug_mode=debug_mode,
|
||||
)
|
||||
cmd: list[str] = [
|
||||
sys.executable,
|
||||
'-c', code,
|
||||
]
|
||||
# breakpoint()
|
||||
kwargs = {}
|
||||
if platform.system() == 'Windows':
|
||||
# without this, tests hang on windows forever
|
||||
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
|
||||
proc: subprocess.Popen = testdir.popen(
|
||||
cmd,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
# TODO! we should poll for the registry socket-bind to take place
|
||||
# and only once that's done yield to the requester!
|
||||
# -[ ] TCP: use the `._root.open_root_actor()`::`ping_tpt_socket()`
|
||||
# closure!
|
||||
# -[ ] UDS: can we do something similar for 'pinging" the
|
||||
# file-socket?
|
||||
#
|
||||
global _PROC_SPAWN_WAIT
|
||||
# UDS sockets are **really** fast to bind()/listen()/connect()
|
||||
# so it's often required that we delay a bit more starting
|
||||
# the first actor-tree..
|
||||
if tpt_proto == 'uds':
|
||||
_PROC_SPAWN_WAIT += 1.6
|
||||
|
||||
if _non_linux and ci_env:
|
||||
_PROC_SPAWN_WAIT += 1
|
||||
|
||||
# XXX, allow time for the sub-py-proc to boot up.
|
||||
# !TODO, see ping-polling ideas above!
|
||||
time.sleep(_PROC_SPAWN_WAIT)
|
||||
|
||||
assert not proc.returncode
|
||||
yield proc
|
||||
sig_prog(proc, _INT_SIGNAL)
|
||||
|
||||
# XXX! yeah.. just be reaaal careful with this bc sometimes it
|
||||
# can lock up on the `_io.BufferedReader` and hang..
|
||||
stderr: str = proc.stderr.read().decode()
|
||||
stdout: str = proc.stdout.read().decode()
|
||||
if (
|
||||
stderr
|
||||
or
|
||||
stdout
|
||||
):
|
||||
print(
|
||||
f'Daemon actor tree produced output:\n'
|
||||
f'{proc.args}\n'
|
||||
f'\n'
|
||||
f'stderr: {stderr!r}\n'
|
||||
f'stdout: {stdout!r}\n'
|
||||
)
|
||||
|
||||
if (rc := proc.returncode) != -2:
|
||||
msg: str = (
|
||||
f'Daemon actor tree was not cancelled !?\n'
|
||||
f'proc.args: {proc.args!r}\n'
|
||||
f'proc.returncode: {rc!r}\n'
|
||||
)
|
||||
if rc < 0:
|
||||
raise RuntimeError(msg)
|
||||
|
||||
test_log.error(msg)
|
||||
# NOTE, the `daemon` fixture (+ its `_wait_for_daemon_ready`
|
||||
# helper + the post-yield teardown drain logic) has been
|
||||
# moved to `tests/discovery/conftest.py` since 100% of its
|
||||
# consumers are discovery-protocol tests now living under
|
||||
# that subdir. See:
|
||||
# - `tests/discovery/test_multi_program.py`
|
||||
# - `tests/discovery/test_registrar.py`
|
||||
# - `tests/discovery/test_tpt_bind_addrs.py`
|
||||
|
||||
|
||||
# @pytest.fixture(autouse=True)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
'''
|
||||
from __future__ import annotations
|
||||
import platform
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import time
|
||||
from typing import (
|
||||
|
|
@ -56,6 +58,7 @@ type PexpectSpawner = Callable[
|
|||
@pytest.fixture
|
||||
def spawn(
|
||||
start_method: str,
|
||||
loglevel: str,
|
||||
testdir: pytest.Pytester,
|
||||
reg_addr: tuple[str, int],
|
||||
|
||||
|
|
@ -65,9 +68,19 @@ def spawn(
|
|||
run an `./examples/..` script by name.
|
||||
|
||||
'''
|
||||
if start_method != 'trio':
|
||||
supported_spawners: set[str] = {
|
||||
'trio',
|
||||
# `examples/debugging/<script>.py` picks up the spawn
|
||||
# backend via the `TRACTOR_SPAWN_METHOD` env-var which
|
||||
# is honored inside `tractor._root.open_root_actor()`,
|
||||
# so no per-script edits are required.
|
||||
'main_thread_forkserver',
|
||||
'subint_forkserver',
|
||||
}
|
||||
if start_method not in supported_spawners:
|
||||
pytest.skip(
|
||||
'`pexpect` based tests only supported on `trio` backend'
|
||||
f'`pexpect` based tests NOT supported on spawning-backend: {start_method!r}\n'
|
||||
f'supported-spawners: {supported_spawners!r}'
|
||||
)
|
||||
|
||||
def unset_colors():
|
||||
|
|
@ -79,21 +92,64 @@ def spawn(
|
|||
https://docs.python.org/3/using/cmdline.html#using-on-controlling-color
|
||||
|
||||
'''
|
||||
import os
|
||||
# disable colored tbs
|
||||
os.environ['PYTHON_COLORS'] = '0'
|
||||
# disable all ANSI color output
|
||||
# os.environ['NO_COLOR'] = '1'
|
||||
# ?TODO, doesn't seem to disable prompt color
|
||||
# for `pdbp`?
|
||||
|
||||
def set_spawn_method(
|
||||
start_method: str,
|
||||
):
|
||||
'''
|
||||
Drive the actor-spawn backend inside the spawned
|
||||
`examples/debugging/<script>.py` subproc via env-var
|
||||
(consumed by `tractor._root.open_root_actor()`),
|
||||
without requiring per-script CLI plumbing.
|
||||
|
||||
'''
|
||||
os.environ['TRACTOR_SPAWN_METHOD'] = start_method
|
||||
|
||||
def set_loglevel(
|
||||
loglevel: str|None,
|
||||
):
|
||||
'''
|
||||
Forward the test-suite parametrized `loglevel` into the
|
||||
spawned `examples/debugging/<script>.py` subproc via
|
||||
env-var (consumed by `tractor._root.open_root_actor()`),
|
||||
so console verbosity can be cranked or silenced from
|
||||
the test harness without per-script edits.
|
||||
|
||||
'''
|
||||
if loglevel:
|
||||
os.environ['TRACTOR_LOGLEVEL'] = loglevel
|
||||
else:
|
||||
os.environ.pop('TRACTOR_LOGLEVEL', None)
|
||||
|
||||
spawned: PexpectSpawner|None = None
|
||||
|
||||
def _spawn(
|
||||
cmd: str,
|
||||
expect_timeout: float = 4,
|
||||
start_method: str = start_method,
|
||||
loglevel: str|None = None,
|
||||
**mkcmd_kwargs,
|
||||
) -> pty_spawn.spawn:
|
||||
'''
|
||||
Inner closure handed to consumer tests to invoke
|
||||
`pytest.Pytester.spawn`
|
||||
|
||||
'''
|
||||
nonlocal spawned
|
||||
unset_colors()
|
||||
set_spawn_method(start_method=start_method)
|
||||
set_loglevel(
|
||||
loglevel=loglevel,
|
||||
# ?TODO^ when should this be set by `--ll <level>` ?
|
||||
# by default we apply 'error' but there should be a diff
|
||||
# vs. when the flag IS NOT passed?
|
||||
)
|
||||
spawned = testdir.spawn(
|
||||
cmd=mk_cmd(
|
||||
cmd,
|
||||
|
|
@ -137,6 +193,14 @@ def spawn(
|
|||
if ptyproc.isalive():
|
||||
ptyproc.kill(signal.SIGKILL)
|
||||
|
||||
# Scope our env-var mutations to this single fixture invocation
|
||||
# — both `TRACTOR_SPAWN_METHOD` and `TRACTOR_LOGLEVEL` are
|
||||
# honored by `tractor._root.open_root_actor()` so leaking them
|
||||
# past this test could inadvertently re-route a later in-process
|
||||
# tractor test's spawn-backend / loglevel.
|
||||
os.environ.pop('TRACTOR_SPAWN_METHOD', None)
|
||||
os.environ.pop('TRACTOR_LOGLEVEL', None)
|
||||
|
||||
# TODO? ensure we've cleaned up any UDS-paths?
|
||||
# breakpoint()
|
||||
|
||||
|
|
@ -146,24 +210,40 @@ def spawn(
|
|||
ids='ctl-c={}'.format,
|
||||
)
|
||||
def ctlc(
|
||||
request,
|
||||
request: pytest.FixtureRequest,
|
||||
ci_env: bool,
|
||||
|
||||
start_method: str,
|
||||
) -> bool:
|
||||
'''
|
||||
Parametrize and optionally skip tests which handle
|
||||
ctlc-in-`pdbp`-REPL testing scenarios; certain spawners and actor-tree depths
|
||||
cope very poorly with this..
|
||||
|
||||
use_ctlc = request.param
|
||||
In particular the spawning backends from `multiprocessing` are
|
||||
fragile, as can be the default `trio` spawner under certain
|
||||
conditions where SIGINT is relayed down the entire subproc tree.
|
||||
|
||||
'''
|
||||
use_ctlc: bool = request.param
|
||||
node = request.node
|
||||
markers = node.own_markers
|
||||
for mark in markers:
|
||||
if mark.name == 'has_nested_actors':
|
||||
if (
|
||||
mark.name == 'has_nested_actors'
|
||||
and
|
||||
start_method not in {
|
||||
# TODO, any spawners we should try again?
|
||||
# - [ ] 'trio' but WITHOUT the SIGINT handler setup
|
||||
# per subproc?
|
||||
# 'main_thread_forkserver',
|
||||
}
|
||||
):
|
||||
pytest.skip(
|
||||
f'Test {node} has nested actors and fails with Ctrl-C.\n'
|
||||
f'The test can sometimes run fine locally but until'
|
||||
' we solve' 'this issue this CI test will be xfail:\n'
|
||||
'https://github.com/goodboy/tractor/issues/320'
|
||||
)
|
||||
|
||||
if (
|
||||
mark.name == 'ctlcs_bish'
|
||||
and
|
||||
|
|
@ -190,13 +270,10 @@ def ctlc(
|
|||
|
||||
def expect(
|
||||
child,
|
||||
|
||||
# normally a `pdb` prompt by default
|
||||
patt: str,
|
||||
|
||||
patt: str, # often a `pdbp`-prompt
|
||||
**kwargs,
|
||||
|
||||
) -> None:
|
||||
) -> str:
|
||||
'''
|
||||
Expect wrapper that prints last seen console
|
||||
data before failing.
|
||||
|
|
@ -207,6 +284,8 @@ def expect(
|
|||
patt,
|
||||
**kwargs,
|
||||
)
|
||||
before = str(child.before.decode())
|
||||
return before
|
||||
except TIMEOUT:
|
||||
before = str(child.before.decode())
|
||||
print(before)
|
||||
|
|
@ -216,6 +295,26 @@ def expect(
|
|||
PROMPT = r"\(Pdb\+\)"
|
||||
|
||||
|
||||
# Strip terminal color / ANSI-VT100 escape sequences so
|
||||
# substring matching against REPL + traceback output stays
|
||||
# robust to color leakage — Python 3.13's colored tracebacks,
|
||||
# `pdbp`'s pygments highlighting, etc. — even when
|
||||
# `PYTHON_COLORS=0` (set in the `spawn` fixture) isn't honored
|
||||
# by every renderer in the spawned subproc.
|
||||
# Regex per https://stackoverflow.com/a/14693789
|
||||
_ansi_re: re.Pattern = re.compile(
|
||||
r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])'
|
||||
)
|
||||
|
||||
|
||||
def ansi_strip(text: str) -> str:
|
||||
'''
|
||||
Remove ANSI/VT100 escape sequences from `text`.
|
||||
|
||||
'''
|
||||
return _ansi_re.sub('', text)
|
||||
|
||||
|
||||
def in_prompt_msg(
|
||||
child: SpawnBase,
|
||||
parts: list[str],
|
||||
|
|
@ -235,7 +334,7 @@ def in_prompt_msg(
|
|||
'''
|
||||
__tracebackhide__: bool = False
|
||||
|
||||
before: str = str(child.before.decode())
|
||||
before: str = ansi_strip(str(child.before.decode()))
|
||||
for part in parts:
|
||||
if part not in before:
|
||||
if pause_on_false:
|
||||
|
|
@ -255,16 +354,19 @@ def in_prompt_msg(
|
|||
return True
|
||||
|
||||
|
||||
# TODO: todo support terminal color-chars stripping so we can match
|
||||
# against call stack frame output from the the 'll' command the like!
|
||||
# -[ ] SO answer for stipping ANSI codes: https://stackoverflow.com/a/14693789
|
||||
# NB: color-char stripping (so we can match against call-stack
|
||||
# frame output from the `ll` command and the like) is handled by
|
||||
# `ansi_strip()` applied inside `in_prompt_msg()` + below.
|
||||
def assert_before(
|
||||
child: SpawnBase,
|
||||
patts: list[str],
|
||||
|
||||
**kwargs,
|
||||
) -> str:
|
||||
'''
|
||||
Assert a patter is in `child.before.decode() -> str`,
|
||||
return the full `.before` output on success.
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
__tracebackhide__: bool = False
|
||||
|
||||
assert in_prompt_msg(
|
||||
|
|
@ -275,7 +377,8 @@ def assert_before(
|
|||
err_on_false=True,
|
||||
**kwargs
|
||||
)
|
||||
return str(child.before.decode())
|
||||
before: str = ansi_strip(str(child.before.decode()))
|
||||
return before
|
||||
|
||||
|
||||
def do_ctlc(
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from pexpect.exceptions import (
|
|||
TIMEOUT,
|
||||
EOF,
|
||||
)
|
||||
import tractor
|
||||
|
||||
from .conftest import (
|
||||
do_ctlc,
|
||||
|
|
@ -343,6 +344,7 @@ def test_subactor_breakpoint(
|
|||
def test_multi_subactors(
|
||||
spawn,
|
||||
ctlc: bool,
|
||||
set_fork_aware_capture,
|
||||
):
|
||||
'''
|
||||
Multiple subactors, both erroring and
|
||||
|
|
@ -487,11 +489,12 @@ def test_multi_subactors(
|
|||
def test_multi_daemon_subactors(
|
||||
spawn,
|
||||
loglevel: str,
|
||||
ctlc: bool
|
||||
ctlc: bool,
|
||||
set_fork_aware_capture,
|
||||
):
|
||||
'''
|
||||
Multiple daemon subactors, both erroring and breakpointing within a
|
||||
stream.
|
||||
Multiple daemon subactors, both erroring and breakpointing within
|
||||
a stream.
|
||||
|
||||
'''
|
||||
non_linux = _non_linux
|
||||
|
|
@ -604,7 +607,10 @@ def test_multi_daemon_subactors(
|
|||
child,
|
||||
bp_forev_parts,
|
||||
)
|
||||
except AssertionError:
|
||||
except (
|
||||
# AssertionError, # TODO? rm since never raised?
|
||||
ValueError,
|
||||
):
|
||||
before: str = assert_before(
|
||||
child,
|
||||
name_error_parts,
|
||||
|
|
@ -765,6 +771,8 @@ def test_multi_subactors_root_errors(
|
|||
def test_multi_nested_subactors_error_through_nurseries(
|
||||
ci_env: bool,
|
||||
spawn: PexpectSpawner,
|
||||
is_forking_spawner: bool,
|
||||
test_log: tractor.log.StackLevelAdapter,
|
||||
|
||||
# TODO: address debugger issue for nested tree:
|
||||
# https://github.com/goodboy/tractor/issues/320
|
||||
|
|
@ -781,16 +789,25 @@ def test_multi_nested_subactors_error_through_nurseries(
|
|||
# A test (below) has now been added to explicitly verify this is
|
||||
# fixed.
|
||||
|
||||
child = spawn('multi_nested_subactors_error_up_through_nurseries')
|
||||
child = spawn(
|
||||
'multi_nested_subactors_error_up_through_nurseries',
|
||||
loglevel='pdb',
|
||||
)
|
||||
last_send_char: str|None = None
|
||||
|
||||
# timed_out_early: bool = False
|
||||
# inflate pexpect waits under CPU throttle — incl. the
|
||||
# sustained-load power-cap invisible to static freq reads — so
|
||||
# a slow-to-boot child REPL doesn't trip a false `TIMEOUT`.
|
||||
# See `scripts/cpu-perf-check`.
|
||||
from ..conftest import cpu_perf_headroom
|
||||
headroom: float = cpu_perf_headroom()
|
||||
|
||||
for (
|
||||
i,
|
||||
send_char,
|
||||
) in enumerate(itertools.cycle(['c', 'q'])):
|
||||
|
||||
timeout: float = -1
|
||||
timeout: float = child.timeout
|
||||
if (
|
||||
_non_linux
|
||||
and
|
||||
|
|
@ -803,49 +820,85 @@ def test_multi_nested_subactors_error_through_nurseries(
|
|||
elif i == 0:
|
||||
timeout = 5
|
||||
|
||||
# XXX forking backends may take longer due to
|
||||
# determinstic IPC cancellation.
|
||||
if is_forking_spawner:
|
||||
timeout += 4
|
||||
|
||||
if headroom != 1.:
|
||||
timeout *= headroom
|
||||
|
||||
try:
|
||||
child.expect(
|
||||
PROMPT,
|
||||
timeout=timeout,
|
||||
)
|
||||
delay: float = 0.1
|
||||
test_log.info('Sleeping {delay!r} before next send-chart..')
|
||||
time.sleep(delay)
|
||||
last_send_char: str = send_char
|
||||
child.sendline(send_char)
|
||||
time.sleep(0.01)
|
||||
time.sleep(delay)
|
||||
|
||||
# script finally exited with tb on console.
|
||||
except EOF:
|
||||
test_log.info(
|
||||
f'Breaking from send-char loop'
|
||||
f'last_send_char: {last_send_char!r}\n'
|
||||
)
|
||||
break
|
||||
|
||||
# boxed source errors
|
||||
expect_patts: list[str] = [
|
||||
"NameError: name 'doggypants' is not defined",
|
||||
"tractor._exceptions.RemoteActorError:",
|
||||
"('name_error'",
|
||||
|
||||
# first level subtrees
|
||||
# "tractor._exceptions.RemoteActorError: ('spawner0'",
|
||||
"src_uid=('spawner0'",
|
||||
|
||||
# "tractor._exceptions.RemoteActorError: ('spawner1'",
|
||||
|
||||
# propagation of errors up through nested subtrees
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_0'",
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_1'",
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_2'",
|
||||
# ^-NOTE-^ old RAE repr, new one is below with a field
|
||||
# showing the src actor's uid.
|
||||
"src_uid=('spawn_until_2'",
|
||||
]
|
||||
# XXX, I HAVE NO IDEA why these patts only show on the
|
||||
# `trio`-spawner but it seems to have something to do with
|
||||
# what gets dumped in prior-prompt latches somehow??
|
||||
# TODO for claude, explain and or work through how this is
|
||||
# happening but ONLY WHEN RUN FROM THE TEST, bc when i try to
|
||||
# run the test script manually the correct output ALWAYS seems
|
||||
# to be in the last `str(child.before.decode())` output !?!?
|
||||
if (
|
||||
not is_forking_spawner
|
||||
and
|
||||
last_send_char == 'q'
|
||||
):
|
||||
expect_patts += [
|
||||
# expect the pdb-quit exc.
|
||||
"bdb.BdbQuit",
|
||||
# BUT WHY these dude!?
|
||||
"src_uid=('spawn_until_0'",
|
||||
"relay_uid=('spawn_until_1'",
|
||||
]
|
||||
|
||||
assert_before(
|
||||
child,
|
||||
[ # boxed source errors
|
||||
"NameError: name 'doggypants' is not defined",
|
||||
"tractor._exceptions.RemoteActorError:",
|
||||
"('name_error'",
|
||||
"bdb.BdbQuit",
|
||||
|
||||
# first level subtrees
|
||||
# "tractor._exceptions.RemoteActorError: ('spawner0'",
|
||||
"src_uid=('spawner0'",
|
||||
|
||||
# "tractor._exceptions.RemoteActorError: ('spawner1'",
|
||||
|
||||
# propagation of errors up through nested subtrees
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_0'",
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_1'",
|
||||
# "tractor._exceptions.RemoteActorError: ('spawn_until_2'",
|
||||
# ^-NOTE-^ old RAE repr, new one is below with a field
|
||||
# showing the src actor's uid.
|
||||
"src_uid=('spawn_until_0'",
|
||||
"relay_uid=('spawn_until_1'",
|
||||
"src_uid=('spawn_until_2'",
|
||||
]
|
||||
expect_patts,
|
||||
)
|
||||
expect(child, EOF)
|
||||
|
||||
|
||||
@pytest.mark.timeout(15)
|
||||
# @pytest.mark.timeout(15)
|
||||
@has_nested_actors
|
||||
def test_root_nursery_cancels_before_child_releases_tty_lock(
|
||||
spawn,
|
||||
start_method,
|
||||
ctlc: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -1144,7 +1197,12 @@ def test_shield_pause(
|
|||
"('cancelled_before_pause'", # actor name
|
||||
_repl_fail_msg,
|
||||
"trio.Cancelled",
|
||||
"raise Cancelled._create()",
|
||||
# trio >=0.30 raises via a multi-line
|
||||
# `raise Cancelled._create(source=.., reason=..,
|
||||
# source_task=..)` (cancel-reason metadata), so
|
||||
# match the open-paren form only, NOT the legacy
|
||||
# bare `()`.
|
||||
"raise Cancelled._create(",
|
||||
|
||||
# we should be handling a taskc inside
|
||||
# the first `.port_mortem()` sin-shield!
|
||||
|
|
@ -1162,7 +1220,12 @@ def test_shield_pause(
|
|||
"('root'", # actor name
|
||||
_repl_fail_msg,
|
||||
"trio.Cancelled",
|
||||
"raise Cancelled._create()",
|
||||
# trio >=0.30 raises via a multi-line
|
||||
# `raise Cancelled._create(source=.., reason=..,
|
||||
# source_task=..)` (cancel-reason metadata), so
|
||||
# match the open-paren form only, NOT the legacy
|
||||
# bare `()`.
|
||||
"raise Cancelled._create(",
|
||||
|
||||
# handling a taskc inside the first unshielded
|
||||
# `.port_mortem()`.
|
||||
|
|
@ -1187,7 +1250,11 @@ def test_ctxep_pauses_n_maybe_ipc_breaks(
|
|||
mashed and zombie reaper kills sub with no hangs.
|
||||
|
||||
'''
|
||||
child = spawn('subactor_bp_in_ctx')
|
||||
child = spawn(
|
||||
'subactor_bp_in_ctx',
|
||||
loglevel='devx'
|
||||
# ^XXX REQUIRED for below patt matching!
|
||||
)
|
||||
child.expect(PROMPT)
|
||||
|
||||
# 3 iters for the `gen()` pause-points
|
||||
|
|
@ -1277,7 +1344,11 @@ def test_crash_handling_within_cancelled_root_actor(
|
|||
call.
|
||||
|
||||
'''
|
||||
child = spawn('root_self_cancelled_w_error')
|
||||
child = spawn(
|
||||
'root_self_cancelled_w_error',
|
||||
loglevel='cancel',
|
||||
# ^XXX REQUIRED for below patt matching!
|
||||
)
|
||||
child.expect(PROMPT)
|
||||
|
||||
assert_before(
|
||||
|
|
|
|||
|
|
@ -63,19 +63,31 @@ def test_pause_from_sync(
|
|||
`examples/debugging/sync_bp.py`
|
||||
|
||||
'''
|
||||
child = spawn('sync_bp')
|
||||
# XXX required for `breakpoint()` overload and
|
||||
# thus`tractor.devx.pause_from_sync()`.
|
||||
pytest.importorskip('greenback')
|
||||
child = spawn(
|
||||
'sync_bp',
|
||||
loglevel='pdb', # XXX pattern matching
|
||||
)
|
||||
|
||||
# first `sync_pause()` after nurseries open
|
||||
child.expect(PROMPT)
|
||||
assert_before(
|
||||
_before: str = assert_before(
|
||||
child,
|
||||
[
|
||||
# pre-prompt line
|
||||
_pause_msg,
|
||||
"<Task '__main__.main'",
|
||||
# devx-loglevel
|
||||
# "imported <module 'greenback' from",
|
||||
# "successfully scheduled `._pause()` in `trio` thread on behalf of <Task",
|
||||
|
||||
_pause_msg, # pre-prompt line
|
||||
"('root'",
|
||||
"<Task '__main__.main'",
|
||||
"tractor.pause_from_sync()",
|
||||
]
|
||||
)
|
||||
# XXX `enable_stack_on_sig=False` in script
|
||||
assert 'stackscope' not in _before
|
||||
if ctlc:
|
||||
do_ctlc(child)
|
||||
# ^NOTE^ subactor not spawned yet; don't need extra delay.
|
||||
|
|
@ -85,18 +97,18 @@ def test_pause_from_sync(
|
|||
# first `await tractor.pause()` inside `p.open_context()` body
|
||||
child.expect(PROMPT)
|
||||
|
||||
# XXX shouldn't see gb loaded message with PDB loglevel!
|
||||
# assert not in_prompt_msg(
|
||||
# child,
|
||||
# ['`greenback` portal opened!'],
|
||||
# )
|
||||
# should be same root task
|
||||
assert_before(
|
||||
child,
|
||||
[
|
||||
# XXX should see gb loaded with devx-loglevel.
|
||||
# "`greenback` portal opened!",
|
||||
# "Activated `greenback` for `tractor.pause_from_sync()` support!",
|
||||
|
||||
_pause_msg,
|
||||
"<Task '__main__.main'",
|
||||
"('root'",
|
||||
"<Task '__main__.main'",
|
||||
"tractor.pause()",
|
||||
]
|
||||
)
|
||||
|
||||
|
|
@ -127,17 +139,17 @@ def test_pause_from_sync(
|
|||
# `Lock.acquire()`-ed
|
||||
# (NOT both, which will result in REPL clobbering!)
|
||||
attach_patts: dict[str, list[str]] = {
|
||||
'subactor': [
|
||||
"'start_n_sync_pause'",
|
||||
"('subactor'",
|
||||
"|_<Task 'start_n_sync_pause'": [
|
||||
"|_('subactor'",
|
||||
"tractor.pause_from_sync()",
|
||||
],
|
||||
'inline_root_bg_thread': [
|
||||
"<Thread(inline_root_bg_thread",
|
||||
"|_<Thread(inline_root_bg_thread": [
|
||||
"('root'",
|
||||
"breakpoint(hide_tb=hide_tb)",
|
||||
],
|
||||
'start_soon_root_bg_thread': [
|
||||
"<Thread(start_soon_root_bg_thread",
|
||||
"('root'",
|
||||
"|_<Thread(start_soon_root_bg_thread": [
|
||||
"|_('root'",
|
||||
"tractor.pause_from_sync()",
|
||||
],
|
||||
}
|
||||
conts: int = 0 # for debugging below matching logic on failure
|
||||
|
|
@ -260,6 +272,9 @@ def test_sync_pause_from_aio_task(
|
|||
`examples/debugging/asycio_bp.py`
|
||||
|
||||
'''
|
||||
# XXX required for `breakpoint()` overload and
|
||||
# thus`tractor.devx.pause_from_sync()`.
|
||||
pytest.importorskip('greenback')
|
||||
child = spawn('asyncio_bp')
|
||||
|
||||
# RACE on whether trio/asyncio task bps first
|
||||
|
|
|
|||
|
|
@ -0,0 +1,178 @@
|
|||
'''
|
||||
Tests for `tractor.devx._proctitle` (per-actor `setproctitle`)
|
||||
and the intrinsic-signal sub-actor detection in
|
||||
`tractor._testing._reap`.
|
||||
|
||||
The proctitle is set in `tractor._child._actor_child_main()`
|
||||
after `Actor` construction, so any spawned sub-actor process
|
||||
should:
|
||||
|
||||
- have `argv[0]` (== `/proc/<pid>/cmdline`) start with
|
||||
`<_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.
|
||||
|
||||
`set_actor_proctitle()` itself is also unit-tested in-process
|
||||
to verify the format string.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
import platform
|
||||
|
||||
import psutil
|
||||
import pytest
|
||||
import trio
|
||||
import tractor
|
||||
|
||||
from tractor.runtime._runtime import Actor
|
||||
from tractor.devx._proctitle import (
|
||||
set_actor_proctitle,
|
||||
_def_prefix,
|
||||
)
|
||||
from tractor._testing._reap import (
|
||||
_is_tractor_subactor,
|
||||
_read_cmdline,
|
||||
_read_comm,
|
||||
)
|
||||
|
||||
|
||||
_non_linux: bool = platform.system() != 'Linux'
|
||||
|
||||
|
||||
def test_set_actor_proctitle_format():
|
||||
'''
|
||||
`set_actor_proctitle()` returns the canonical
|
||||
`<_def_prefix>[<aid.reprol()>]` form (currently
|
||||
`_subactor[…]`) and actually mutates the running
|
||||
proc's title.
|
||||
|
||||
'''
|
||||
pytest.importorskip(
|
||||
'setproctitle',
|
||||
reason='`setproctitle` is an optional runtime dep',
|
||||
)
|
||||
import setproctitle
|
||||
|
||||
# save + restore so we don't pollute pytest's own title
|
||||
saved: str = setproctitle.getproctitle()
|
||||
try:
|
||||
actor = Actor(
|
||||
name='unit_test_actor',
|
||||
uuid='1027301b-a0e3-430e-8806-a5279f21abe6',
|
||||
)
|
||||
title: str = set_actor_proctitle(actor)
|
||||
|
||||
# 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
|
||||
# drops the name is also caught).
|
||||
assert 'unit_test_actor' in title
|
||||
|
||||
# actually set on the running proc
|
||||
assert setproctitle.getproctitle() == title
|
||||
|
||||
finally:
|
||||
setproctitle.setproctitle(saved)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
_non_linux,
|
||||
reason=(
|
||||
'detection helpers read `/proc/<pid>/{cmdline,comm}` '
|
||||
'which is Linux-specific'
|
||||
),
|
||||
)
|
||||
def test_subactor_proctitle_visible_via_proc():
|
||||
'''
|
||||
Spawn a sub-actor and verify its proc-title is visible
|
||||
via both `/proc/<pid>/cmdline` AND `/proc/<pid>/comm`,
|
||||
AND that `_is_tractor_subactor()` correctly identifies
|
||||
it.
|
||||
|
||||
'''
|
||||
pytest.importorskip('setproctitle')
|
||||
|
||||
async def main() -> dict:
|
||||
async with tractor.open_nursery() as an:
|
||||
portal = await an.start_actor('proctitle_boi')
|
||||
# let the child finish setproctitle in
|
||||
# `_actor_child_main`
|
||||
await trio.sleep(0.3)
|
||||
|
||||
# the sub-actor's pid is on the portal's chan
|
||||
# repr; psutil-walk `me.children()` is simpler.
|
||||
me = psutil.Process()
|
||||
sub_pids: list[int] = [
|
||||
p.pid for p in me.children(recursive=True)
|
||||
]
|
||||
assert sub_pids, (
|
||||
'expected at least one spawned sub-actor pid'
|
||||
)
|
||||
|
||||
results: dict = {}
|
||||
for pid in sub_pids:
|
||||
results[pid] = {
|
||||
'cmdline': _read_cmdline(pid),
|
||||
'comm': _read_comm(pid),
|
||||
'is_tractor': _is_tractor_subactor(pid),
|
||||
}
|
||||
|
||||
await portal.cancel_actor()
|
||||
return results
|
||||
|
||||
found: dict = trio.run(main)
|
||||
|
||||
# at least one of the spawned procs should match the
|
||||
# `proctitle_boi` actor we started; assert the proc-
|
||||
# title shape on it specifically.
|
||||
matched: list[tuple[int, dict]] = [
|
||||
(pid, info)
|
||||
for pid, info in found.items()
|
||||
if 'proctitle_boi' in info['cmdline']
|
||||
]
|
||||
assert matched, (
|
||||
f'no sub-actor pid had a `proctitle_boi` cmdline; '
|
||||
f'all={found}'
|
||||
)
|
||||
|
||||
pid, info = matched[0]
|
||||
# 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
|
||||
# `<_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
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
_non_linux,
|
||||
reason='reads /proc/<pid>/{cmdline,comm}',
|
||||
)
|
||||
def test_is_tractor_subactor_negative():
|
||||
'''
|
||||
`_is_tractor_subactor()` returns False for non-tractor
|
||||
procs (e.g. the pytest test-runner pid itself, which
|
||||
is `python -m pytest …` — no `tractor[` proctitle, no
|
||||
`tractor._child` cmdline).
|
||||
|
||||
'''
|
||||
import os
|
||||
assert _is_tractor_subactor(os.getpid()) is False
|
||||
|
|
@ -21,6 +21,7 @@ import os
|
|||
import signal
|
||||
import time
|
||||
from typing import (
|
||||
Callable,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
|
|
@ -47,7 +48,12 @@ if TYPE_CHECKING:
|
|||
|
||||
@no_macos
|
||||
def test_shield_pause(
|
||||
spawn: PexpectSpawner,
|
||||
spawn: Callable[
|
||||
...,
|
||||
PexpectSpawner,
|
||||
],
|
||||
start_method: str,
|
||||
request: pytest.FixtureRequest,
|
||||
):
|
||||
'''
|
||||
Verify the `tractor.pause()/.post_mortem()` API works inside an
|
||||
|
|
@ -55,8 +61,10 @@ def test_shield_pause(
|
|||
next checkpoint wherein the cancelled will get raised.
|
||||
|
||||
'''
|
||||
child = spawn(
|
||||
'shield_hang_in_sub'
|
||||
child: PexpectSpawner = spawn(
|
||||
'shield_hang_in_sub',
|
||||
loglevel='devx',
|
||||
# ^XXX REQUIRED for below patt matching!
|
||||
)
|
||||
expect(
|
||||
child,
|
||||
|
|
@ -86,38 +94,82 @@ def test_shield_pause(
|
|||
# end-of-tree delimiter
|
||||
"end-of-\('root'",
|
||||
)
|
||||
assert_before(
|
||||
_before: str = assert_before(
|
||||
child,
|
||||
[
|
||||
# 'Srying to dump `stackscope` tree..',
|
||||
# 'Dumping `stackscope` tree for actor',
|
||||
"('root'", # uid line
|
||||
|
||||
# TODO!? this used to show?
|
||||
# TODO!? this in-task-code used to show??
|
||||
# -[ ] mk reproducable for @oremanj?
|
||||
# => SOLVED? by our `trio_token.run_sync_soon()`
|
||||
# approach?
|
||||
#
|
||||
# parent block point (non-shielded)
|
||||
# 'await trio.sleep_forever() # in root',
|
||||
]
|
||||
)
|
||||
expect(
|
||||
child,
|
||||
# end-of-tree delimiter
|
||||
"end-of-\('hanger'",
|
||||
)
|
||||
assert_before(
|
||||
child,
|
||||
[
|
||||
# relay to the sub should be reported
|
||||
'Relaying `SIGUSR1`[10] to sub-actor',
|
||||
|
||||
"('hanger'", # uid line
|
||||
# NOTE, hierarchical-ordering invariant restored by
|
||||
# `_dump_then_relay` (co-scheduled dump+relay on the
|
||||
# trio loop, see `tractor.devx._stackscope`): the
|
||||
# parent's full task-tree prints BEFORE the 'Relaying
|
||||
# `SIGUSR1`' log msg, which prints BEFORE any sub-
|
||||
# actor receives the signal and dumps its own tree.
|
||||
# So the relay log appears BETWEEN `end-of-('root'`
|
||||
# (above) and `end-of-('hanger'` (below).
|
||||
handle_out_of_order: bool = False
|
||||
|
||||
# XXX, when capfd is NOT used we don't expect to
|
||||
# see the logging output from the subactor.
|
||||
if (no_capfd := (start_method in [
|
||||
'main_thread_forkserver',
|
||||
])
|
||||
):
|
||||
opts = request.config.option
|
||||
assert opts.spawn_backend == start_method
|
||||
# ?XXX? i guess the `testdir` fixture "pretends to" reset
|
||||
# this to the default 'fd'??
|
||||
# assert opts.capture in [
|
||||
# 'sys',
|
||||
# 'no',
|
||||
# ]
|
||||
|
||||
if (
|
||||
handle_out_of_order
|
||||
and
|
||||
"end-of-('hanger'" in _before
|
||||
):
|
||||
assert "('hanger'" in _before
|
||||
assert 'Relaying `SIGUSR1`[10] to sub-actor' in _before
|
||||
|
||||
else:
|
||||
_before = expect(
|
||||
child,
|
||||
'Relaying `SIGUSR1`\\[10\\] to sub-actor',
|
||||
)
|
||||
# _before: str = assert_before(
|
||||
# child,
|
||||
# ["('hanger'",] # uid line
|
||||
# )
|
||||
if not no_capfd:
|
||||
expect(
|
||||
child,
|
||||
# end-of-subactor's-tree delimiter
|
||||
"end-of-\('hanger'",
|
||||
)
|
||||
_before: str = assert_before(
|
||||
child,
|
||||
[
|
||||
"('hanger'", # uid line
|
||||
|
||||
# TODO!? SEE ABOVE
|
||||
# hanger LOC where it's shield-halted
|
||||
# 'await trio.sleep_forever() # in subactor',
|
||||
]
|
||||
)
|
||||
|
||||
# TODO!? SEE ABOVE
|
||||
# hanger LOC where it's shield-halted
|
||||
# 'await trio.sleep_forever() # in subactor',
|
||||
]
|
||||
)
|
||||
|
||||
# simulate the user sending a ctl-c to the hanging program.
|
||||
# this should result in the terminator kicking in since
|
||||
|
|
@ -133,14 +185,19 @@ def test_shield_pause(
|
|||
_shutdown_msg,
|
||||
timeout=6,
|
||||
)
|
||||
assert_before(
|
||||
child,
|
||||
[
|
||||
'raise KeyboardInterrupt',
|
||||
expect_on_teardown: list[str] = [
|
||||
'raise KeyboardInterrupt',
|
||||
'Root actor terminated',
|
||||
]
|
||||
if not no_capfd:
|
||||
expect_on_teardown += [
|
||||
# 'Shutting down actor runtime',
|
||||
'#T-800 deployed to collect zombie B0',
|
||||
"'--uid', \"('hanger',",
|
||||
]
|
||||
assert_before(
|
||||
child,
|
||||
expect_on_teardown,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -156,8 +213,10 @@ def test_breakpoint_hook_restored(
|
|||
calls used.
|
||||
|
||||
'''
|
||||
# XXX required for `breakpoint()` overload and
|
||||
# thus`tractor.devx.pause_from_sync()`.
|
||||
pytest.importorskip('greenback')
|
||||
child = spawn('restore_builtin_breakpoint')
|
||||
|
||||
child.expect(PROMPT)
|
||||
try:
|
||||
assert_before(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,223 @@
|
|||
'''
|
||||
Discovery-suite fixtures, including the `daemon`
|
||||
remote-registrar subprocess used by the multi-program
|
||||
discovery tests.
|
||||
|
||||
Lives here (vs. the parent `tests/conftest.py`)
|
||||
because `daemon` is a discovery-protocol primitive —
|
||||
boots a separate `tractor.run_daemon()` process whose
|
||||
sole purpose is to serve as a registrar peer for
|
||||
discovery-roundtrip tests. Pytest fixtures inherit
|
||||
DOWNWARD through conftest hierarchy, so anything
|
||||
under `tests/discovery/` automatically picks this up.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
import os
|
||||
import platform
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import tractor
|
||||
|
||||
from ..conftest import (
|
||||
sig_prog,
|
||||
_INT_SIGNAL,
|
||||
_non_linux,
|
||||
)
|
||||
|
||||
|
||||
def _wait_for_daemon_ready(
|
||||
reg_addr: tuple,
|
||||
tpt_proto: str,
|
||||
*,
|
||||
deadline: float = 10.0,
|
||||
poll_interval: float = 0.05,
|
||||
proc: subprocess.Popen|None = None,
|
||||
) -> None:
|
||||
'''
|
||||
Active-poll the daemon's bind address until it
|
||||
accepts a connection (proving it has called
|
||||
`bind() + listen()` and is ready to handle IPC).
|
||||
|
||||
Replaces the historical blind `time.sleep()` in the
|
||||
`daemon` fixture which was racy under load — see
|
||||
`ai/conc-anal/test_register_duplicate_name_daemon_connect_race_issue.md`.
|
||||
|
||||
Uses stdlib `socket` directly (no trio runtime
|
||||
bootstrap cost) — sufficient because
|
||||
`tractor.run_daemon()` doesn't return from
|
||||
bootstrap until the runtime is fully ready to
|
||||
accept IPC.
|
||||
|
||||
Raises `TimeoutError` on `deadline` exceeded. If
|
||||
`proc` is given, ALSO raises early if the daemon
|
||||
process exits non-zero before the deadline (catches
|
||||
daemon-startup-crash that the blind sleep used to
|
||||
silently mask).
|
||||
|
||||
'''
|
||||
end: float = time.monotonic() + deadline
|
||||
last_exc: Exception|None = None
|
||||
while time.monotonic() < end:
|
||||
# Daemon-died-during-startup early-exit. Without
|
||||
# this, a crashed-on-import daemon would just
|
||||
# eat the full deadline before raising opaque
|
||||
# TimeoutError.
|
||||
if proc is not None and proc.poll() is not None:
|
||||
raise RuntimeError(
|
||||
f'Daemon proc exited (rc={proc.returncode}) '
|
||||
f'before becoming ready to accept on '
|
||||
f'{reg_addr!r}'
|
||||
)
|
||||
try:
|
||||
if tpt_proto == 'tcp':
|
||||
# `socket.create_connection` does the
|
||||
# `socket() + connect()` dance with a
|
||||
# builtin timeout — perfect primitive
|
||||
# for a one-shot probe.
|
||||
with socket.create_connection(
|
||||
reg_addr,
|
||||
timeout=poll_interval,
|
||||
):
|
||||
return
|
||||
else:
|
||||
# UDS — `reg_addr` is a `(filedir, sockname)`
|
||||
# tuple per `tractor.ipc._uds.UDSAddress.unwrap`.
|
||||
sockpath: str = os.path.join(*reg_addr)
|
||||
sock = socket.socket(socket.AF_UNIX)
|
||||
try:
|
||||
sock.settimeout(poll_interval)
|
||||
sock.connect(sockpath)
|
||||
return
|
||||
finally:
|
||||
sock.close()
|
||||
except (
|
||||
ConnectionRefusedError,
|
||||
FileNotFoundError,
|
||||
OSError,
|
||||
socket.timeout,
|
||||
) as exc:
|
||||
last_exc = exc
|
||||
time.sleep(poll_interval)
|
||||
raise TimeoutError(
|
||||
f'Daemon never accepted on {reg_addr!r} within '
|
||||
f'{deadline}s (last connect-attempt exc: '
|
||||
f'{last_exc!r})'
|
||||
)
|
||||
|
||||
|
||||
# TODO: factor into @cm and move to `._testing`?
|
||||
@pytest.fixture
|
||||
def daemon(
|
||||
debug_mode: bool,
|
||||
loglevel: str,
|
||||
testdir: pytest.Pytester,
|
||||
reg_addr: tuple[str, int],
|
||||
tpt_proto: str,
|
||||
ci_env: bool,
|
||||
test_log: tractor.log.StackLevelAdapter,
|
||||
|
||||
) -> subprocess.Popen:
|
||||
'''
|
||||
Run a daemon root actor as a separate actor-process
|
||||
tree and "remote registrar" for discovery-protocol
|
||||
related tests.
|
||||
|
||||
'''
|
||||
# XXX: too much logging will lock up the subproc (smh)
|
||||
if loglevel in ('trace', 'debug'):
|
||||
test_log.warning(
|
||||
f'Test harness log level is too verbose: {loglevel!r}\n'
|
||||
f'Reducing to INFO level..'
|
||||
)
|
||||
loglevel: str = 'info'
|
||||
|
||||
code: str = (
|
||||
"import tractor; "
|
||||
"tractor.run_daemon([], "
|
||||
"registry_addrs={reg_addrs}, "
|
||||
"enable_transports={enable_tpts}, "
|
||||
"debug_mode={debug_mode}, "
|
||||
"loglevel={ll})"
|
||||
).format(
|
||||
reg_addrs=str([reg_addr]),
|
||||
enable_tpts=str([tpt_proto]),
|
||||
ll="'{}'".format(loglevel) if loglevel else None,
|
||||
debug_mode=debug_mode,
|
||||
)
|
||||
cmd: list[str] = [
|
||||
sys.executable,
|
||||
'-c', code,
|
||||
]
|
||||
kwargs = {}
|
||||
if platform.system() == 'Windows':
|
||||
# without this, tests hang on windows forever
|
||||
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
|
||||
proc: subprocess.Popen = testdir.popen(
|
||||
cmd,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
# Active-poll the daemon's bind address until it's
|
||||
# ready to accept connections — replaces the legacy
|
||||
# blind `time.sleep(2.2)` which was racy under load
|
||||
# (see
|
||||
# `ai/conc-anal/test_register_duplicate_name_daemon_connect_race_issue.md`).
|
||||
#
|
||||
# Per-test deadline scales with platform: macOS/CI
|
||||
# gets extra headroom; Linux dev boxes need very
|
||||
# little.
|
||||
deadline: float = (
|
||||
15.0 if (_non_linux and ci_env)
|
||||
else 10.0
|
||||
)
|
||||
_wait_for_daemon_ready(
|
||||
reg_addr=reg_addr,
|
||||
tpt_proto=tpt_proto,
|
||||
deadline=deadline,
|
||||
proc=proc,
|
||||
)
|
||||
|
||||
assert not proc.returncode
|
||||
yield proc
|
||||
sig_prog(proc, _INT_SIGNAL)
|
||||
|
||||
# XXX! yeah.. just be reaaal careful with this bc
|
||||
# sometimes it can lock up on the `_io.BufferedReader`
|
||||
# and hang..
|
||||
#
|
||||
# NB, drain happens at TEARDOWN (post-yield), so the
|
||||
# test body has its chance to read `proc.stderr`
|
||||
# FIRST. Reading here AFTER would silently swallow
|
||||
# the daemon's stderr output and break tests that
|
||||
# assert on it (e.g. `test_abort_on_sigint`).
|
||||
stderr: str = proc.stderr.read().decode()
|
||||
stdout: str = proc.stdout.read().decode()
|
||||
if (
|
||||
stderr
|
||||
or
|
||||
stdout
|
||||
):
|
||||
print(
|
||||
f'Daemon actor tree produced output:\n'
|
||||
f'{proc.args}\n'
|
||||
f'\n'
|
||||
f'stderr: {stderr!r}\n'
|
||||
f'stdout: {stdout!r}\n'
|
||||
)
|
||||
|
||||
if (rc := proc.returncode) != -2:
|
||||
msg: str = (
|
||||
f'Daemon actor tree was not cancelled !?\n'
|
||||
f'proc.args: {proc.args!r}\n'
|
||||
f'proc.returncode: {rc!r}\n'
|
||||
)
|
||||
if rc < 0:
|
||||
raise RuntimeError(msg)
|
||||
|
||||
test_log.error(msg)
|
||||
|
|
@ -0,0 +1,355 @@
|
|||
"""
|
||||
Multiple python programs invoking the runtime.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import platform
|
||||
import subprocess
|
||||
import time
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
import tractor
|
||||
from tractor._testing import (
|
||||
tractor_test,
|
||||
)
|
||||
from tractor import (
|
||||
current_actor,
|
||||
Actor,
|
||||
Context,
|
||||
Portal,
|
||||
)
|
||||
from tractor.runtime import _state
|
||||
from ..conftest import (
|
||||
sig_prog,
|
||||
_INT_SIGNAL,
|
||||
_INT_RETURN_CODE,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from tractor.msg import Aid
|
||||
from tractor.discovery._addr import (
|
||||
UnwrappedAddress,
|
||||
)
|
||||
|
||||
|
||||
_non_linux: bool = platform.system() != 'Linux'
|
||||
|
||||
|
||||
# NOTE, multi-program tests historically triggered both
|
||||
# UDS sock-file leaks (daemon-subproc SIGKILL paths) AND
|
||||
# trio `WakeupSocketpair.drain()` busy-loops
|
||||
# (`test_register_duplicate_name`). Track + detect
|
||||
# per-test as a regression net.
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
'track_orphaned_uds_per_test',
|
||||
'detect_runaway_subactors_per_test',
|
||||
)
|
||||
|
||||
|
||||
def test_abort_on_sigint(
|
||||
daemon: subprocess.Popen,
|
||||
):
|
||||
assert daemon.returncode is None
|
||||
time.sleep(0.1)
|
||||
sig_prog(daemon, _INT_SIGNAL)
|
||||
assert daemon.returncode == _INT_RETURN_CODE
|
||||
|
||||
# XXX: oddly, couldn't get capfd.readouterr() to work here?
|
||||
if platform.system() != 'Windows':
|
||||
# don't check stderr on windows as its empty when sending CTRL_C_EVENT
|
||||
assert "KeyboardInterrupt" in str(daemon.stderr.read())
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_cancel_remote_registrar(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
):
|
||||
assert not current_actor().is_registrar
|
||||
async with tractor.get_registry(reg_addr) as portal:
|
||||
await portal.cancel_actor()
|
||||
|
||||
time.sleep(0.1)
|
||||
# the registrar channel server is cancelled but not its main task
|
||||
assert daemon.returncode is None
|
||||
|
||||
# no registrar socket should exist
|
||||
with pytest.raises(OSError):
|
||||
async with tractor.get_registry(reg_addr) as portal:
|
||||
pass
|
||||
|
||||
|
||||
def test_register_duplicate_name(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
):
|
||||
# bug-class-3 breadcrumbs: the *last* `[CANCEL]` line that
|
||||
# appears under `--ll cancel`/`TRACTOR_LOG_FILE=...` names the
|
||||
# cancel-cascade boundary that's parked. Pair with
|
||||
# `_trio_main` entry/exit breadcrumbs in
|
||||
# `tractor/spawn/_entry.py` to triangulate the swallow point.
|
||||
log = tractor.log.get_logger('tractor.tests.test_multi_program')
|
||||
|
||||
async def main():
|
||||
log.cancel('test_register_duplicate_name: enter `main()`')
|
||||
try:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'actor nursery opened'
|
||||
)
|
||||
|
||||
assert not current_actor().is_registrar
|
||||
|
||||
p1 = await an.start_actor('doggy')
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'spawned doggy #1'
|
||||
)
|
||||
p2 = await an.start_actor('doggy')
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'spawned doggy #2'
|
||||
)
|
||||
|
||||
async with tractor.wait_for_actor('doggy') as portal:
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'`wait_for_actor` returned'
|
||||
)
|
||||
assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)
|
||||
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'ABOUT TO CALL `an.cancel()`'
|
||||
)
|
||||
await an.cancel()
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'`an.cancel()` returned'
|
||||
)
|
||||
finally:
|
||||
log.cancel(
|
||||
'test_register_duplicate_name: '
|
||||
'`open_nursery.__aexit__` returned, leaving `main()`'
|
||||
)
|
||||
|
||||
# XXX, run manually since we want to start this root **after**
|
||||
# the other "daemon" program with it's own root.
|
||||
trio.run(main)
|
||||
|
||||
|
||||
# `n_dups` in {4, 8} both expose the SAME pre-existing race:
|
||||
# under rapid same-name spawning against a forkserver +
|
||||
# registrar, ONE of the spawned doggies `sys.exit(2)`s during
|
||||
# boot before completing parent-handshake. Surfaces now (post
|
||||
# the spawn-time `wait_for_peer_or_proc_death` fix) as
|
||||
# `ActorFailure rc=2`; previously it was silently masked by
|
||||
# the handshake-wait parking forever.
|
||||
#
|
||||
# Larger `n_dups` widens the race window so the boot-race
|
||||
# fires more often — n_dups=4 hits ~always, n_dups=8 hits
|
||||
# occasionally. Both xfail(strict=False) so the cancel-cascade
|
||||
# regression-check still passes when the boot-race happens
|
||||
# NOT to fire.
|
||||
#
|
||||
# Tracked separately in,
|
||||
# https://github.com/goodboy/tractor/issues/456
|
||||
_DOGGY_BOOT_RACE_XFAIL = pytest.mark.xfail(
|
||||
strict=False,
|
||||
reason=(
|
||||
'doggy boot-race rc=2 under rapid same-name '
|
||||
'spawn — separate bug from cancel-cascade'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'n_dups',
|
||||
[
|
||||
2,
|
||||
pytest.param(4, marks=_DOGGY_BOOT_RACE_XFAIL),
|
||||
pytest.param(8, marks=_DOGGY_BOOT_RACE_XFAIL),
|
||||
],
|
||||
ids=lambda n: f'n_dups={n}',
|
||||
)
|
||||
def test_dup_name_cancel_cascade_escalates_to_hard_kill(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
n_dups: int,
|
||||
):
|
||||
'''
|
||||
Regression for the duplicate-name cancel-cascade hang under
|
||||
`tcp+main_thread_forkserver`.
|
||||
|
||||
When N actors share a single name and the parent calls
|
||||
`an.cancel()`, the daemon registrar gets N `register_actor` RPCs
|
||||
in tight succession. Under TCP+MTF, kernel-level socket-buffer
|
||||
contention can push at least one sub-actor's cancel-RPC ack past
|
||||
`Portal.cancel_timeout` (default 0.5s).
|
||||
|
||||
Pre-fix, `Portal.cancel_actor()` silently returned `False` on
|
||||
that timeout, the supervisor's outer `move_on_after(3)` never
|
||||
fired (each per-portal task always returned ≤0.5s, never
|
||||
exceeded 3s), and `soft_kill()`'s `await wait_func(proc)` parked
|
||||
forever — deadlocking nursery `__aexit__`.
|
||||
|
||||
Post-fix, `Portal.cancel_actor()` raises `ActorTooSlowError` on
|
||||
the bounded-wait timeout, and `ActorNursery.cancel()`'s
|
||||
per-child wrapper escalates to `proc.terminate()` (hard-kill).
|
||||
The full nursery teardown therefore stays bounded even under
|
||||
pathological timing.
|
||||
|
||||
`n_dups` is parametrized to widen the race window — more
|
||||
same-name siblings = more concurrent register-RPCs at the
|
||||
daemon = higher probability of hitting the contention path.
|
||||
|
||||
'''
|
||||
log = tractor.log.get_logger(
|
||||
'tractor.tests.test_multi_program'
|
||||
)
|
||||
|
||||
# outer hard ceiling: a regression should fail-fast, NOT hang
|
||||
# the test session for minutes. Budget scales with `n_dups`
|
||||
# since each extra same-name sibling adds ~spawn-cost +
|
||||
# potential cancel-ack-timeout escalation latency under
|
||||
# TCP+forkserver. ~5s/sibling + 15s baseline gives plenty of
|
||||
# headroom while still failing-loud on a real hang.
|
||||
fail_after_s: int = 15 + (5 * n_dups)
|
||||
|
||||
async def main():
|
||||
log.cancel(
|
||||
f'enter `main()` n_dups={n_dups}'
|
||||
)
|
||||
with trio.fail_after(fail_after_s):
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
portals: list[Portal] = []
|
||||
for i in range(n_dups):
|
||||
p: Portal = await an.start_actor('doggy')
|
||||
portals.append(p)
|
||||
log.cancel(
|
||||
f'spawned doggy #{i + 1}/{n_dups}'
|
||||
)
|
||||
|
||||
# at least one of the N must be discoverable by
|
||||
# name; doesn't matter which one (registrar will
|
||||
# have last-wins semantics under same-name).
|
||||
async with tractor.wait_for_actor('doggy') as portal:
|
||||
expected_uids = {p.channel.uid for p in portals}
|
||||
assert portal.channel.uid in expected_uids
|
||||
|
||||
# critical section: this MUST return within
|
||||
# `fail_after_s` even when one or more cancel-RPC
|
||||
# acks time out. Pre-fix, this hangs forever.
|
||||
log.cancel('about to call `an.cancel()`')
|
||||
await an.cancel()
|
||||
log.cancel('`an.cancel()` returned')
|
||||
|
||||
# post-teardown sanity: every child proc must be reaped.
|
||||
# If escalation worked, even timed-out cancel-RPCs would
|
||||
# have triggered `proc.terminate()` and the procs are dead.
|
||||
for p in portals:
|
||||
# `Portal.channel.connected()` -> False once the
|
||||
# underlying chan disconnected (clean exit OR
|
||||
# hard-killed proc both produce disconnect).
|
||||
assert not p.channel.connected(), (
|
||||
f'Portal chan still connected post-teardown?\n'
|
||||
f'{p.channel}'
|
||||
)
|
||||
|
||||
trio.run(main)
|
||||
|
||||
|
||||
@tractor.context
|
||||
async def get_root_portal(
|
||||
ctx: Context,
|
||||
):
|
||||
'''
|
||||
Connect back to the root actor manually (using `._discovery` API)
|
||||
and ensure it's contact info is the same as our immediate parent.
|
||||
|
||||
'''
|
||||
sub: Actor = current_actor()
|
||||
rtvs: dict = _state._runtime_vars
|
||||
raddrs: list[UnwrappedAddress] = rtvs['_root_addrs']
|
||||
|
||||
# await tractor.pause()
|
||||
# XXX, in case the sub->root discovery breaks you might need
|
||||
# this (i know i did Xp)!!
|
||||
# from tractor.devx import mk_pdb
|
||||
# mk_pdb().set_trace()
|
||||
|
||||
assert (
|
||||
len(raddrs) == 1
|
||||
and
|
||||
list(sub._parent_chan.raddr.unwrap()) in raddrs
|
||||
)
|
||||
|
||||
# connect back to our immediate parent which should also
|
||||
# be the actor-tree's root.
|
||||
from tractor.discovery._api import get_root
|
||||
ptl: Portal
|
||||
async with get_root() as ptl:
|
||||
root_aid: Aid = ptl.chan.aid
|
||||
parent_ptl: Portal = current_actor().get_parent()
|
||||
assert (
|
||||
root_aid.name == 'root'
|
||||
and
|
||||
parent_ptl.chan.aid == root_aid
|
||||
)
|
||||
await ctx.started()
|
||||
|
||||
|
||||
def test_non_registrar_spawns_child(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
loglevel: str,
|
||||
debug_mode: bool,
|
||||
ci_env: bool,
|
||||
):
|
||||
'''
|
||||
Ensure a non-regristar (serving) root actor can spawn a sub and
|
||||
that sub can connect back (manually) to it's rent that is the
|
||||
root without issue.
|
||||
|
||||
More or less this audits the global contact info in
|
||||
`._state._runtime_vars`.
|
||||
|
||||
'''
|
||||
async def main():
|
||||
|
||||
# XXX, since apparently on macos in GH's CI it can be a race
|
||||
# with the `daemon` registrar on grabbing the socket-addr..
|
||||
if ci_env and _non_linux:
|
||||
await trio.sleep(.5)
|
||||
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
loglevel=loglevel,
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
|
||||
actor: Actor = tractor.current_actor()
|
||||
assert not actor.is_registrar
|
||||
sub_ptl: Portal = await an.start_actor(
|
||||
name='sub',
|
||||
enable_modules=[__name__],
|
||||
)
|
||||
|
||||
async with sub_ptl.open_context(
|
||||
get_root_portal,
|
||||
) as (ctx, _):
|
||||
print('Waiting for `sub` to connect back to us..')
|
||||
|
||||
await an.cancel()
|
||||
|
||||
# XXX, run manually since we want to start this root **after**
|
||||
# the other "daemon" program with it's own root.
|
||||
trio.run(main)
|
||||
|
|
@ -14,6 +14,7 @@ import psutil
|
|||
import pytest
|
||||
import subprocess
|
||||
import tractor
|
||||
from tractor.devx import dump_on_hang
|
||||
from tractor.trionics import collapse_eg
|
||||
from tractor._testing import tractor_test
|
||||
from tractor.discovery._addr import wrap_address
|
||||
|
|
@ -21,6 +22,20 @@ from tractor.discovery._multiaddr import mk_maddr
|
|||
import trio
|
||||
|
||||
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
'reap_subactors_per_test',
|
||||
# NOTE, registrar tests stress the discovery
|
||||
# roundtrip (find_actor / wait_for_actor) which
|
||||
# historically left orphaned UDS sock-files when
|
||||
# subactor `hard_kill` SIGKILL'd, and which
|
||||
# exercises the same trio `WakeupSocketpair`
|
||||
# peer-disconnect path that triggered the
|
||||
# busy-loop bug class.
|
||||
'track_orphaned_uds_per_test',
|
||||
'detect_runaway_subactors_per_test',
|
||||
)
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_reg_then_unreg(
|
||||
reg_addr: tuple,
|
||||
|
|
@ -105,19 +120,6 @@ async def hi():
|
|||
return the_line.format(tractor.current_actor().name)
|
||||
|
||||
|
||||
async def say_hello(
|
||||
other_actor: str,
|
||||
reg_addr: tuple[str, int],
|
||||
):
|
||||
await trio.sleep(1) # wait for other actor to spawn
|
||||
async with tractor.find_actor(
|
||||
other_actor,
|
||||
registry_addrs=[reg_addr],
|
||||
) as portal:
|
||||
assert portal is not None
|
||||
return await portal.run(__name__, 'hi')
|
||||
|
||||
|
||||
async def say_hello_use_wait(
|
||||
other_actor: str,
|
||||
reg_addr: tuple[str, int],
|
||||
|
|
@ -131,14 +133,17 @@ async def say_hello_use_wait(
|
|||
return result
|
||||
|
||||
|
||||
@tractor_test
|
||||
@tractor_test(
|
||||
timeout=7,
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
'func',
|
||||
[say_hello,
|
||||
say_hello_use_wait]
|
||||
'ria_fn',
|
||||
[
|
||||
say_hello_use_wait,
|
||||
]
|
||||
)
|
||||
async def test_trynamic_trio(
|
||||
func: Callable,
|
||||
ria_fn: Callable,
|
||||
start_method: str,
|
||||
reg_addr: tuple,
|
||||
):
|
||||
|
|
@ -151,13 +156,13 @@ async def test_trynamic_trio(
|
|||
print("Alright... Action!")
|
||||
|
||||
donny = await n.run_in_actor(
|
||||
func,
|
||||
ria_fn,
|
||||
other_actor='gretchen',
|
||||
reg_addr=reg_addr,
|
||||
name='donny',
|
||||
)
|
||||
gretchen = await n.run_in_actor(
|
||||
func,
|
||||
ria_fn,
|
||||
other_actor='donny',
|
||||
reg_addr=reg_addr,
|
||||
name='gretchen',
|
||||
|
|
@ -319,6 +324,14 @@ async def spawn_and_check_registry(
|
|||
assert actor.aid.uid in registry
|
||||
|
||||
|
||||
async def with_timeout(
|
||||
main: Callable,
|
||||
timeout: float = 6,
|
||||
):
|
||||
with trio.fail_after(timeout):
|
||||
await main()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_signal', [False, True])
|
||||
@pytest.mark.parametrize('with_streaming', [False, True])
|
||||
def test_subactors_unregister_on_cancel(
|
||||
|
|
@ -335,6 +348,7 @@ def test_subactors_unregister_on_cancel(
|
|||
'''
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
trio.run(
|
||||
# with_timeout,
|
||||
partial(
|
||||
spawn_and_check_registry,
|
||||
reg_addr,
|
||||
|
|
@ -364,6 +378,7 @@ def test_subactors_unregister_on_cancel_remote_daemon(
|
|||
'''
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
trio.run(
|
||||
with_timeout,
|
||||
partial(
|
||||
spawn_and_check_registry,
|
||||
reg_addr,
|
||||
|
|
@ -515,12 +530,43 @@ async def kill_transport(
|
|||
|
||||
|
||||
|
||||
# ?TODO, do a OSc style signalling test on this?
|
||||
# -[ ] doesn't work for fork backends
|
||||
# @pytest.mark.parametrize('use_signal', [False, True])
|
||||
#
|
||||
# Wall-clock bound via `pytest-timeout` (`method='thread'`).
|
||||
# Under `--spawn-backend=subint` this test can wedge in an
|
||||
# un-Ctrl-C-able state (abandoned-subint + shared-GIL
|
||||
# starvation → signal-wakeup-fd pipe fills → SIGINT silently
|
||||
# dropped; see `ai/conc-anal/subint_sigint_starvation_issue.md`).
|
||||
# `method='thread'` is specifically required because `signal`-
|
||||
# method SIGALRM suffers the same GIL-starvation path and
|
||||
# wouldn't fire the Python-level handler.
|
||||
# At timeout the plugin hard-kills the pytest process — that's
|
||||
# the intended behavior here; the alternative is an unattended
|
||||
# suite run that never returns.
|
||||
# @pytest.mark.timeout(
|
||||
# 30,
|
||||
# # NOTE should be a 2.1s happy path.
|
||||
# # XXX for `main_thread_forkserver` this is SUPER SENSITIVE
|
||||
# # so keep it higher to avoid flaky runs..
|
||||
# method='thread',
|
||||
# )
|
||||
@pytest.mark.skipon_spawn_backend(
|
||||
'subint',
|
||||
# 'main_thread_forkserver',
|
||||
reason=(
|
||||
'XXX SUBINT HANGING TEST XXX\n'
|
||||
'See outstanding issue(s)\n'
|
||||
# TODO, put issue link!
|
||||
)
|
||||
)
|
||||
def test_stale_entry_is_deleted(
|
||||
debug_mode: bool,
|
||||
daemon: subprocess.Popen,
|
||||
start_method: str,
|
||||
reg_addr: tuple,
|
||||
# set_fork_aware_capture,
|
||||
):
|
||||
'''
|
||||
Ensure that when a stale entry is detected in the registrar's
|
||||
|
|
@ -529,7 +575,6 @@ def test_stale_entry_is_deleted(
|
|||
|
||||
'''
|
||||
async def main():
|
||||
|
||||
name: str = 'transport_fails_actor'
|
||||
_reg_ptl: tractor.Portal
|
||||
an: tractor.ActorNursery
|
||||
|
|
@ -562,4 +607,67 @@ def test_stale_entry_is_deleted(
|
|||
await ptl.cancel_actor()
|
||||
await an.cancel()
|
||||
|
||||
trio.run(main)
|
||||
# XXX, for tracing if this starts being flaky again..
|
||||
#
|
||||
timeout: float = 4
|
||||
async def _timeout_main():
|
||||
with trio.move_on_after(timeout) as cs:
|
||||
await main()
|
||||
|
||||
if (
|
||||
cs.cancel_called
|
||||
and
|
||||
debug_mode
|
||||
):
|
||||
await tractor.pause()
|
||||
|
||||
# TODO, remove once the `[subint]` variant no longer hangs.
|
||||
#
|
||||
# Status (as of Phase B hard-kill landing):
|
||||
#
|
||||
# - `[trio]`/`[mp_*]` variants: completes normally; `dump_on_hang`
|
||||
# is a no-op safety net here.
|
||||
#
|
||||
# - `[subint]` variant: hangs indefinitely AND is un-Ctrl-C-able.
|
||||
# `strace -p <pytest_pid>` while in the hang reveals a silently-
|
||||
# dropped SIGINT — the C signal handler tries to write the
|
||||
# signum byte to Python's signal-wakeup fd and gets `EAGAIN`,
|
||||
# meaning the pipe is full (nobody's draining it).
|
||||
#
|
||||
# Root-cause chain: our hard-kill in `spawn._subint` abandoned
|
||||
# the driver OS-thread (which is `daemon=True`) after the soft-
|
||||
# kill timeout, but the *sub-interpreter* inside that thread is
|
||||
# still running `trio.run()` — `_interpreters.destroy()` can't
|
||||
# force-stop a running subint (raises `InterpreterError`), and
|
||||
# legacy-config subints share the main GIL. The abandoned subint
|
||||
# starves the parent's trio event loop from iterating often
|
||||
# enough to drain its wakeup pipe → SIGINT silently drops.
|
||||
#
|
||||
# This is structurally a CPython-level limitation: there's no
|
||||
# public force-destroy primitive for a running subint. We
|
||||
# escape on the harness side via a SIGINT-loop in the `daemon`
|
||||
# fixture teardown (killing the bg registrar subproc closes its
|
||||
# end of the IPC, which eventually unblocks a recv in main trio,
|
||||
# which lets the loop drain the wakeup pipe). Long-term fix path:
|
||||
# msgspec PEP 684 support (jcrist/msgspec#563) → isolated-mode
|
||||
# subints with per-interp GIL.
|
||||
#
|
||||
# Full analysis:
|
||||
# `ai/conc-anal/subint_sigint_starvation_issue.md`
|
||||
#
|
||||
# See also the *sibling* hang class documented in
|
||||
# `ai/conc-anal/subint_cancel_delivery_hang_issue.md` — same
|
||||
# subint backend, different root cause (Ctrl-C-able hang, main
|
||||
# trio loop iterating fine; ours to fix, not CPython's).
|
||||
# Reproduced by `tests/test_subint_cancellation.py
|
||||
# ::test_subint_non_checkpointing_child`.
|
||||
#
|
||||
# Kept here (and not behind a `pytestmark.skip`) so we can still
|
||||
# inspect the dump file if the hang ever returns after a refactor.
|
||||
# `pytest`'s stderr capture eats `faulthandler` output otherwise,
|
||||
# so we route `dump_on_hang` to a file.
|
||||
with dump_on_hang(
|
||||
seconds=timeout*2,
|
||||
path=f'/tmp/test_stale_entry_is_deleted_{start_method}.dump',
|
||||
):
|
||||
trio.run(_timeout_main)
|
||||
|
|
|
|||
|
|
@ -59,15 +59,18 @@ async def chk_tpts(
|
|||
)
|
||||
def test_root_passes_tpt_to_sub(
|
||||
tpt_proto_key: str,
|
||||
tpt_proto: str,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
# XXX NOTE, the `reg_addr` addr won't be the same type as the
|
||||
# `tpt_proto_key` would deliver here unless you pass `--tpt-proto
|
||||
# <tpt_proto_key>` on the CLI.
|
||||
#
|
||||
# if tpt_proto_key == 'uds':
|
||||
# breakpoint()
|
||||
# `reg_addr` is sourced from the CLI `--tpt-proto={tpt_proto}`,
|
||||
# so when the parametrized `tpt_proto_key` differs, the test
|
||||
# asks the runtime to `enable_transports=[<other_proto>]` while
|
||||
# pointing `registry_addrs` at a `reg_addr` of the wrong proto.
|
||||
# The layer-2 guard in `open_root_actor` is expected to fail
|
||||
# fast with `ValueError` on this mismatch (rather than the prior
|
||||
# silent hang during the registrar handshake).
|
||||
proto_mismatch: bool = (tpt_proto_key != tpt_proto)
|
||||
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
|
|
@ -99,4 +102,14 @@ def test_root_passes_tpt_to_sub(
|
|||
# shudown sub-actor(s)
|
||||
await an.cancel()
|
||||
|
||||
trio.run(main)
|
||||
if proto_mismatch:
|
||||
# mismatched proto must raise `ValueError` from the
|
||||
# `open_root_actor` runtime guard before any subactor spawn.
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
trio.run(main)
|
||||
msg: str = str(excinfo.value)
|
||||
assert 'enable_transports' in msg
|
||||
assert 'registry_addrs' in msg
|
||||
assert tpt_proto_key in msg or tpt_proto in msg
|
||||
else:
|
||||
trio.run(main)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ from tractor.msg._ops import (
|
|||
limit_plds,
|
||||
)
|
||||
|
||||
|
||||
def enc_nsp(obj: Any) -> Any:
|
||||
actor: Actor = tractor.current_actor(
|
||||
err_on_no_runtime=False,
|
||||
|
|
@ -617,6 +618,17 @@ def test_ext_types_over_ipc(
|
|||
debug_mode: bool,
|
||||
pld_spec: Union[Type],
|
||||
add_hooks: bool,
|
||||
|
||||
set_fork_aware_capture,
|
||||
# ^^XXX? for forking spawners
|
||||
|
||||
# capfd: pytest.CaptureFixture,
|
||||
# ^^NOTE, super interesting that if
|
||||
# we disable this below then the tpt-layer
|
||||
# suffers as an "unclean EOF"??
|
||||
# ?TODO, determine why/how that mks sense when addressing,
|
||||
# https://github.com/pytest-dev/pytest/issues/14444
|
||||
#
|
||||
):
|
||||
'''
|
||||
Ensure we can support extension types coverted using
|
||||
|
|
@ -725,18 +737,26 @@ def test_ext_types_over_ipc(
|
|||
|
||||
await p.cancel_actor()
|
||||
|
||||
async def fa_main():
|
||||
with (
|
||||
trio.fail_after(2),
|
||||
# ?TODO, investigate? see NOTE above..
|
||||
# capfd.disabled(),
|
||||
):
|
||||
await main()
|
||||
|
||||
if (
|
||||
NamespacePath in pld_types
|
||||
and
|
||||
add_hooks
|
||||
):
|
||||
trio.run(main)
|
||||
trio.run(fa_main)
|
||||
|
||||
else:
|
||||
with pytest.raises(
|
||||
expected_exception=tractor.RemoteActorError,
|
||||
) as excinfo:
|
||||
trio.run(main)
|
||||
trio.run(fa_main)
|
||||
|
||||
exc = excinfo.value
|
||||
# bc `.started(nsp: NamespacePath)` will raise
|
||||
|
|
|
|||
|
|
@ -55,12 +55,37 @@ async def maybe_expect_raises(
|
|||
raises: BaseException|None = None,
|
||||
ensure_in_message: list[str]|None = None,
|
||||
post_mortem: bool = False,
|
||||
timeout: int = 3,
|
||||
# NOTE, `None` selects a backend-aware default below —
|
||||
# see `_BACKEND_TIMEOUT_DEFAULTS` for rationale. Caller
|
||||
# can override with an explicit value to opt out.
|
||||
timeout: int|None = None,
|
||||
) -> None:
|
||||
'''
|
||||
Async wrapper for ensuring errors propagate from the inner scope.
|
||||
|
||||
'''
|
||||
if timeout is None:
|
||||
# Pick a backend-aware default. Fork-based backends
|
||||
# (`main_thread_forkserver`) need much more headroom
|
||||
# because actor spawn + IPC ctx-exit + msg-validation
|
||||
# error path takes longer than under `trio` backend
|
||||
# — especially under cross-pytest-stream contention
|
||||
# (#451). `test_basic_payload_spec` empirically:
|
||||
# - 3s flaked all-valid variant (`TooSlowError`)
|
||||
# - 8s flaked `invalid-return` variant
|
||||
# (`Cancelled` surfaced instead of `MsgTypeError`
|
||||
# because `fail_after` fired mid-error-path)
|
||||
# - 15s flaked under cross-stream contention
|
||||
# 30s for fork-based gives plenty of headroom while
|
||||
# still failing-loud on a genuine hang. Other
|
||||
# backends keep the original 3s.
|
||||
from tractor.spawn import _spawn as _spawn_mod
|
||||
timeout = (
|
||||
30
|
||||
if _spawn_mod._spawn_method == 'main_thread_forkserver'
|
||||
else 3
|
||||
)
|
||||
|
||||
if tractor.debug_mode():
|
||||
timeout += 999
|
||||
|
||||
|
|
@ -259,6 +284,11 @@ def test_basic_payload_spec(
|
|||
return_value: str|None,
|
||||
started_value: int|PldMsg,
|
||||
pld_check_started_value: bool,
|
||||
|
||||
set_fork_aware_capture,
|
||||
# ^XXX TODO? for forking spawners, seems to prevent hangs when
|
||||
# --capture=sys not set, but only for a while then the problem
|
||||
# accumulates?
|
||||
):
|
||||
'''
|
||||
Validate the most basic `PldRx` msg-type-spec semantics around
|
||||
|
|
|
|||
|
|
@ -5,10 +5,15 @@ Advanced streaming patterns using bidirectional streams and contexts.
|
|||
from collections import Counter
|
||||
import itertools
|
||||
import platform
|
||||
from typing import Type
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
import tractor
|
||||
from tractor._testing.trace import (
|
||||
AfkAlarmWTraceFactory,
|
||||
FailAfterWTraceFactory,
|
||||
)
|
||||
|
||||
|
||||
def is_win():
|
||||
|
|
@ -76,9 +81,7 @@ async def subscribe(
|
|||
|
||||
|
||||
async def consumer(
|
||||
|
||||
subs: list[str],
|
||||
|
||||
) -> None:
|
||||
|
||||
uid = tractor.current_actor().uid
|
||||
|
|
@ -108,59 +111,200 @@ async def consumer(
|
|||
print(f'{uid} got: {value}')
|
||||
|
||||
|
||||
def test_dynamic_pub_sub():
|
||||
# NOTE: deliberately NOT using `@pytest.mark.timeout(...)` —
|
||||
# both pytest-timeout enforcement modes break trio under
|
||||
# fork-based backends:
|
||||
#
|
||||
# - `method='signal'` (SIGALRM): the handler synchronously
|
||||
# raises `Failed` in trio's main thread mid-`epoll.poll()`,
|
||||
# leaves `GLOBAL_RUN_CONTEXT` half-installed ("Trio guest
|
||||
# run got abandoned"), and EVERY subsequent `trio.run()`
|
||||
# in the same pytest process bails with
|
||||
# `RuntimeError: Attempted to call run() from inside a
|
||||
# run()` — session-wide poison.
|
||||
#
|
||||
# - `method='thread'`: calls `_thread.interrupt_main()`
|
||||
# raising `KeyboardInterrupt` into the main thread. Under
|
||||
# fork-based backends with mid-cascade fd-juggling the KBI
|
||||
# can escape trio's `KIManager` and bubble out of pytest
|
||||
# itself — kills the WHOLE session.
|
||||
#
|
||||
# Instead we use `trio.fail_after()` INSIDE `main()` below:
|
||||
# trio's own `Cancelled`/`TooSlowError` machinery handles the
|
||||
# timeout, cleanly unwinds the actor nursery's cancel
|
||||
# cascade, and only fails the single test (no cross-test
|
||||
# state corruption either way).
|
||||
#
|
||||
# `pyproject.toml`'s default `timeout = 200` is still a
|
||||
# last-resort safety net.
|
||||
@pytest.mark.parametrize(
|
||||
'expect_cancel_exc', [
|
||||
KeyboardInterrupt,
|
||||
trio.TooSlowError,
|
||||
],
|
||||
ids=lambda item:
|
||||
f'expect_user_exc_raised={item.__name__}'
|
||||
)
|
||||
def test_dynamic_pub_sub(
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
test_log: tractor.log.StackLevelAdapter,
|
||||
reap_subactors_per_test: int,
|
||||
expect_cancel_exc: Type[BaseException],
|
||||
|
||||
is_forking_spawner: bool,
|
||||
set_fork_aware_capture,
|
||||
|
||||
fail_after_w_trace: FailAfterWTraceFactory,
|
||||
afk_alarm_w_trace: AfkAlarmWTraceFactory,
|
||||
):
|
||||
failed_to_raise_report: str = (
|
||||
f'Never got a {expect_cancel_exc!r} ??'
|
||||
)
|
||||
|
||||
global _registry
|
||||
|
||||
from multiprocessing import cpu_count
|
||||
cpus = cpu_count()
|
||||
|
||||
# Hard safety cap via trio's own cancellation. NOTE see the
|
||||
# module-level note on why we avoid `pytest-timeout` for this
|
||||
# test. Picked backend-aware: under `trio` backend spawn is
|
||||
# cheap (~1s for `cpus` actors) but fork-based backends pay
|
||||
# a per-spawn cost (forkserver round-trip + IPC peer-handshake)
|
||||
# that can stack up over `cpus - 1` sequential `n.run_in_actor()`
|
||||
# calls — especially on UDS under cross-pytest contention
|
||||
# (#451 / #452). 4s was flaking right at the edge under fork
|
||||
# backends — bumped to 8s with diag-snapshot-on-timeout via
|
||||
# `fail_after_w_trace` so a borderline run still fails loud
|
||||
# but lands a ptree/wchan/py-spy dump in
|
||||
# `$XDG_CACHE_HOME/tractor/hung-dumps/` for inspection.
|
||||
#
|
||||
# XXX caveat: this is an *inner* trio cancel — its `Cancelled`
|
||||
# cannot reach a task parked in a shielded `await` (e.g. inside
|
||||
# actor-nursery teardown). When the in-band cancel path is
|
||||
# itself buggy (the bug-class-3 `raise KBI` swallow we're
|
||||
# currently chasing) this guard does NOT fire and the test
|
||||
# sits forever until external SIGINT. The `afk_alarm_w_trace`
|
||||
# outer guard below is the AFK-safety counterpart (SIGALRM
|
||||
# raises in the main thread regardless of trio scope state).
|
||||
fail_after_s: float = (
|
||||
8
|
||||
if is_forking_spawner
|
||||
else 20
|
||||
)
|
||||
# inflate under CPU throttle — incl. the sustained-load
|
||||
# power-cap invisible to static freq reads — so a slow box
|
||||
# doesn't trip the deadline. See `scripts/cpu-perf-check`.
|
||||
from .conftest import cpu_perf_headroom
|
||||
headroom: float = cpu_perf_headroom()
|
||||
if headroom != 1.:
|
||||
fail_after_s *= headroom
|
||||
|
||||
async def main():
|
||||
async with tractor.open_nursery() as n:
|
||||
|
||||
# name of this actor will be same as target func
|
||||
await n.run_in_actor(publisher)
|
||||
|
||||
for i, sub in zip(
|
||||
range(cpus - 2),
|
||||
itertools.cycle(_registry.keys())
|
||||
):
|
||||
await n.run_in_actor(
|
||||
consumer,
|
||||
name=f'consumer_{sub}',
|
||||
subs=[sub],
|
||||
# bug-class-3 breadcrumb: tag each level of the cancel path
|
||||
# so when the run hangs and we capture cancel-level logs, the
|
||||
# *last* breadcrumb that fired names the swallow point.
|
||||
test_log.cancel('test_dynamic_pub_sub: enter main()')
|
||||
try:
|
||||
async with fail_after_w_trace(fail_after_s):
|
||||
test_log.cancel(
|
||||
f'test_dynamic_pub_sub: '
|
||||
f'enter `fail_after_w_trace({fail_after_s})` scope'
|
||||
)
|
||||
try:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as n:
|
||||
test_log.cancel(
|
||||
'test_dynamic_pub_sub: '
|
||||
'actor nursery opened'
|
||||
)
|
||||
|
||||
# make one dynamic subscriber
|
||||
await n.run_in_actor(
|
||||
consumer,
|
||||
name='consumer_dynamic',
|
||||
subs=list(_registry.keys()),
|
||||
# name of this actor will be same as target func
|
||||
await n.run_in_actor(publisher)
|
||||
|
||||
for i, sub in zip(
|
||||
range(cpus - 2),
|
||||
itertools.cycle(_registry.keys())
|
||||
):
|
||||
await n.run_in_actor(
|
||||
consumer,
|
||||
name=f'consumer_{sub}',
|
||||
subs=[sub],
|
||||
)
|
||||
|
||||
# make one dynamic subscriber
|
||||
await n.run_in_actor(
|
||||
consumer,
|
||||
name='consumer_dynamic',
|
||||
subs=list(_registry.keys()),
|
||||
)
|
||||
|
||||
# block until "cancelled by user"
|
||||
await trio.sleep(3)
|
||||
test_log.warning(
|
||||
f'Raising user cancel exc: '
|
||||
f'{expect_cancel_exc!r}'
|
||||
)
|
||||
test_log.cancel(
|
||||
f'test_dynamic_pub_sub: '
|
||||
f'ABOUT TO RAISE {expect_cancel_exc!r}'
|
||||
)
|
||||
raise expect_cancel_exc('simulate user cancel!')
|
||||
finally:
|
||||
test_log.cancel(
|
||||
'test_dynamic_pub_sub: '
|
||||
'actor nursery `__aexit__` returned'
|
||||
)
|
||||
test_log.cancel(
|
||||
'test_dynamic_pub_sub: `fail_after` scope exited'
|
||||
)
|
||||
finally:
|
||||
test_log.cancel(
|
||||
'test_dynamic_pub_sub: leaving `main()`'
|
||||
)
|
||||
|
||||
# block until cancelled by user
|
||||
with trio.fail_after(3):
|
||||
await trio.sleep_forever()
|
||||
def _run_and_match():
|
||||
try:
|
||||
trio.run(main)
|
||||
pytest.fail(failed_to_raise_report)
|
||||
except expect_cancel_exc:
|
||||
# parent-side raised the user-cancel exc directly and
|
||||
# it propagated unwrapped; clean path.
|
||||
test_log.exception('Got user-cancel exc AS EXPECTED')
|
||||
except BaseExceptionGroup as err:
|
||||
# under fork-based backends the user-raised cancel
|
||||
# can race with subactor-side stream teardown
|
||||
# (`trio.EndOfChannel` from a publisher's `send()`
|
||||
# whose remote half got cut). The expected exc may
|
||||
# then be nested deeper in the group rather than at
|
||||
# the top level. `BaseExceptionGroup.split()` walks
|
||||
# the exc tree recursively (Python 3.11+).
|
||||
matched, _ = err.split(expect_cancel_exc)
|
||||
if matched is None:
|
||||
pytest.fail(failed_to_raise_report)
|
||||
|
||||
try:
|
||||
trio.run(main)
|
||||
except (
|
||||
trio.TooSlowError,
|
||||
ExceptionGroup,
|
||||
) as err:
|
||||
if isinstance(err, ExceptionGroup):
|
||||
for suberr in err.exceptions:
|
||||
if isinstance(suberr, trio.TooSlowError):
|
||||
break
|
||||
else:
|
||||
pytest.fail('Never got a `TooSlowError` ?')
|
||||
test_log.exception('Got user-cancel exc AS EXPECTED')
|
||||
|
||||
# outer SIGALRM-based guard — survives a shielded-await
|
||||
# deadlock since `signal.alarm` raises in the main thread
|
||||
# regardless of trio's scope state, AND captures a full diag
|
||||
# snapshot to `$XDG_CACHE_HOME/tractor/hung-dumps/` before
|
||||
# re-raising. ONLY armed under fork-based backends since the
|
||||
# bug we're chasing is MTF-specific. Cap = `fail_after_s + 5`
|
||||
# so the trio-native path always wins when it works.
|
||||
if is_forking_spawner:
|
||||
with afk_alarm_w_trace(fail_after_s + 5):
|
||||
_run_and_match()
|
||||
else:
|
||||
_run_and_match()
|
||||
|
||||
|
||||
@tractor.context
|
||||
async def one_task_streams_and_one_handles_reqresp(
|
||||
|
||||
ctx: tractor.Context,
|
||||
|
||||
) -> None:
|
||||
|
||||
await ctx.started()
|
||||
|
|
@ -257,7 +401,8 @@ async def echo_ctx_stream(
|
|||
|
||||
|
||||
def test_sigint_both_stream_types():
|
||||
'''Verify that running a bi-directional and recv only stream
|
||||
'''
|
||||
Verify that running a bi-directional and recv only stream
|
||||
side-by-side will cancel correctly from SIGINT.
|
||||
|
||||
'''
|
||||
|
|
@ -287,9 +432,11 @@ def test_sigint_both_stream_types():
|
|||
assert resp == msg
|
||||
raise KeyboardInterrupt
|
||||
|
||||
# TODO, use pytest.raises() here instead?
|
||||
# (why weren't we originally?)
|
||||
try:
|
||||
trio.run(main)
|
||||
assert 0, "Didn't receive KBI!?"
|
||||
pytest.fail("Didn't receive KBI!?")
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
|
@ -356,7 +503,12 @@ async def inf_streamer(
|
|||
print('streamer exited .open_streamer() block')
|
||||
|
||||
|
||||
# @pytest.mark.timeout(
|
||||
# 6,
|
||||
# method='signal',
|
||||
# )
|
||||
def test_local_task_fanout_from_stream(
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -421,4 +573,9 @@ def test_local_task_fanout_from_stream(
|
|||
|
||||
await p.cancel_actor()
|
||||
|
||||
trio.run(main)
|
||||
async def w_timeout():
|
||||
with trio.fail_after(6):
|
||||
await main()
|
||||
|
||||
# trio.run(main)
|
||||
trio.run(w_timeout)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import signal
|
|||
import platform
|
||||
import time
|
||||
from itertools import repeat
|
||||
from typing import Type
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
|
|
@ -14,6 +15,7 @@ import tractor
|
|||
from tractor._testing import (
|
||||
tractor_test,
|
||||
)
|
||||
from tractor._testing.trace import FailAfterWTraceFactory
|
||||
from .conftest import no_windows
|
||||
|
||||
|
||||
|
|
@ -21,6 +23,46 @@ _non_linux: bool = platform.system() != 'Linux'
|
|||
_friggin_windows: bool = platform.system() == 'Windows'
|
||||
|
||||
|
||||
pytestmark = [
|
||||
# Multi-actor cancel cascades under
|
||||
# `--spawn-backend=subint` trip the abandoned-subint
|
||||
# GIL-hostage class — a stuck subint can starve the
|
||||
# parent's trio loop and block cancel-delivery.
|
||||
# Apply the skip module-wide rather than per-test
|
||||
# since every test here exercises the same cascade.
|
||||
pytest.mark.skipon_spawn_backend(
|
||||
'subint',
|
||||
reason=(
|
||||
'XXX SUBINT GIL-CONTENTION HANGING TEST XXX\n'
|
||||
'Cancel cascades under '
|
||||
'`--spawn-backend=subint` trip the abandoned-subint '
|
||||
'GIL-hostage class — see\n'
|
||||
' - `ai/conc-anal/subint_sigint_starvation_issue.md` '
|
||||
'(GIL-hostage, SIGINT-unresponsive)\n'
|
||||
' - `ai/conc-anal/subint_cancel_delivery_hang_issue.md` '
|
||||
'(sibling: parent parks on dead chan)\n'
|
||||
' - https://github.com/goodboy/tractor/issues/379 '
|
||||
'(subint umbrella)\n'
|
||||
)
|
||||
),
|
||||
pytest.mark.usefixtures(
|
||||
'reap_subactors_per_test',
|
||||
# NOTE, cancellation tests stress the SIGKILL
|
||||
# `hard_kill` path which leaks UDS sock-files when
|
||||
# the subactor's IPC server `finally:` cleanup
|
||||
# doesn't run. Track per-test for blame attribution.
|
||||
'track_orphaned_uds_per_test',
|
||||
# NOTE, cancel-cascade timing races (see
|
||||
# `test_nested_multierrors`) can also leave a
|
||||
# subactor spinning at 100% CPU when its cancel
|
||||
# signal got swallowed mid-handshake. Catches the
|
||||
# runaway-loop class that doesn't leak UDS socks
|
||||
# but burns the box.
|
||||
'detect_runaway_subactors_per_test',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def assert_err(delay=0):
|
||||
await trio.sleep(delay)
|
||||
assert 0
|
||||
|
|
@ -45,7 +87,11 @@ async def do_nuthin():
|
|||
],
|
||||
ids=['no_args', 'unexpected_args'],
|
||||
)
|
||||
def test_remote_error(reg_addr, args_err):
|
||||
def test_remote_error(
|
||||
reg_addr: tuple,
|
||||
args_err: tuple[dict, Type[Exception]],
|
||||
set_fork_aware_capture,
|
||||
):
|
||||
'''
|
||||
Verify an error raised in a subactor that is propagated
|
||||
to the parent nursery, contains the underlying boxed builtin
|
||||
|
|
@ -112,6 +158,8 @@ def test_remote_error(reg_addr, args_err):
|
|||
|
||||
def test_multierror(
|
||||
reg_addr: tuple[str, int],
|
||||
start_method: str, # parametrized
|
||||
set_fork_aware_capture, #: Callable,
|
||||
):
|
||||
'''
|
||||
Verify we raise a ``BaseExceptionGroup`` out of a nursery where
|
||||
|
|
@ -141,31 +189,68 @@ def test_multierror(
|
|||
trio.run(main)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('delay', (0, 0.5))
|
||||
@pytest.mark.parametrize(
|
||||
'num_subactors', range(25, 26),
|
||||
'delay',
|
||||
(0, 0.5),
|
||||
ids='delays={}'.format,
|
||||
)
|
||||
def test_multierror_fast_nursery(reg_addr, start_method, num_subactors, delay):
|
||||
"""Verify we raise a ``BaseExceptionGroup`` out of a nursery where
|
||||
@pytest.mark.parametrize(
|
||||
'num_subactors',
|
||||
range(25, 26),
|
||||
ids= 'num_subs={}'.format,
|
||||
)
|
||||
def test_multierror_fast_nursery(
|
||||
reg_addr: tuple,
|
||||
start_method: str,
|
||||
num_subactors: int,
|
||||
delay: float,
|
||||
set_fork_aware_capture,
|
||||
fail_after_w_trace: FailAfterWTraceFactory,
|
||||
):
|
||||
'''
|
||||
Verify we raise a ``BaseExceptionGroup`` out of a nursery where
|
||||
more then one actor errors and also with a delay before failure
|
||||
to test failure during an ongoing spawning.
|
||||
"""
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as nursery:
|
||||
|
||||
for i in range(num_subactors):
|
||||
await nursery.run_in_actor(
|
||||
assert_err,
|
||||
name=f'errorer{i}',
|
||||
delay=delay
|
||||
)
|
||||
'''
|
||||
async def main():
|
||||
# budget = 2× natural trio-backend cascade time for
|
||||
# 25 errorer subactors (~14s observed). on-timeout
|
||||
# diag snapshot → if the cancel cascade hangs
|
||||
# (observed under MTF backend with N>=14 errorer
|
||||
# subactors) we get a fresh ptree/wchan/py-spy dump
|
||||
# on disk INSTEAD of an opaque pytest timeout-kill.
|
||||
# See `tractor/_testing/trace.py` for the helper.
|
||||
async with fail_after_w_trace(30.0):
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as nursery:
|
||||
|
||||
for i in range(num_subactors):
|
||||
await nursery.run_in_actor(
|
||||
assert_err,
|
||||
name=f'errorer{i}',
|
||||
delay=delay
|
||||
)
|
||||
|
||||
# with pytest.raises(trio.MultiError) as exc_info:
|
||||
with pytest.raises(BaseExceptionGroup) as exc_info:
|
||||
# NOTE, `trio.TooSlowError` from `fail_after_w_trace`
|
||||
# bubbles UN-wrapped if `open_nursery.__aexit__` never
|
||||
# gets re-entered; wrapped inside a `BaseExceptionGroup`
|
||||
# if it did. Accept both shapes so the matcher itself
|
||||
# doesn't lie about *what* failed.
|
||||
with pytest.raises(
|
||||
(BaseExceptionGroup, trio.TooSlowError),
|
||||
) as exc_info:
|
||||
trio.run(main)
|
||||
|
||||
if isinstance(exc_info.value, trio.TooSlowError):
|
||||
pytest.fail(
|
||||
f'cancel cascade hung past 12s '
|
||||
f'(num_subactors={num_subactors}, delay={delay}); '
|
||||
f'see stderr for `fail_after_w_trace` snapshot path'
|
||||
)
|
||||
|
||||
assert exc_info.type == ExceptionGroup
|
||||
err = exc_info.value
|
||||
exceptions = err.exceptions
|
||||
|
|
@ -189,8 +274,15 @@ async def do_nothing():
|
|||
pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mechanism', ['nursery_cancel', KeyboardInterrupt])
|
||||
def test_cancel_single_subactor(reg_addr, mechanism):
|
||||
@pytest.mark.parametrize(
|
||||
'mechanism', [
|
||||
'nursery_cancel',
|
||||
KeyboardInterrupt,
|
||||
])
|
||||
def test_cancel_single_subactor(
|
||||
reg_addr: tuple,
|
||||
mechanism: str|KeyboardInterrupt,
|
||||
):
|
||||
'''
|
||||
Ensure a ``ActorNursery.start_actor()`` spawned subactor
|
||||
cancels when the nursery is cancelled.
|
||||
|
|
@ -232,9 +324,14 @@ async def stream_forever():
|
|||
await trio.sleep(0.01)
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_cancel_infinite_streamer(start_method):
|
||||
|
||||
@tractor_test(
|
||||
timeout=6,
|
||||
)
|
||||
async def test_cancel_infinite_streamer(
|
||||
reg_addr: tuple,
|
||||
start_method: str,
|
||||
set_fork_aware_capture,
|
||||
):
|
||||
# stream for at most 1 seconds
|
||||
with (
|
||||
trio.fail_after(4),
|
||||
|
|
@ -286,11 +383,15 @@ async def test_cancel_infinite_streamer(start_method):
|
|||
'no_daemon_actors_fail_all_run_in_actors_sleep_then_fail',
|
||||
],
|
||||
)
|
||||
@tractor_test
|
||||
@tractor_test(
|
||||
timeout=10,
|
||||
)
|
||||
async def test_some_cancels_all(
|
||||
num_actors_and_errs: tuple,
|
||||
reg_addr: tuple,
|
||||
start_method: str,
|
||||
loglevel: str,
|
||||
set_fork_aware_capture, #: Callable,
|
||||
):
|
||||
'''
|
||||
Verify a subset of failed subactors causes all others in
|
||||
|
|
@ -370,7 +471,10 @@ async def test_some_cancels_all(
|
|||
pytest.fail("Should have gotten a remote assertion error?")
|
||||
|
||||
|
||||
async def spawn_and_error(breadth, depth) -> None:
|
||||
async def spawn_and_error(
|
||||
breadth: int,
|
||||
depth: int,
|
||||
) -> None:
|
||||
name = tractor.current_actor().name
|
||||
async with tractor.open_nursery() as nursery:
|
||||
for i in range(breadth):
|
||||
|
|
@ -395,28 +499,190 @@ async def spawn_and_error(breadth, depth) -> None:
|
|||
await nursery.run_in_actor(*args, **kwargs)
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_nested_multierrors(loglevel, start_method):
|
||||
# NOTE: `main_thread_forkserver` capture-fd hang class is no
|
||||
# longer skipped here — `--capture=sys` (the new `pyproject.toml`
|
||||
# default) sidesteps the pipe-buffer-fill deadlock for
|
||||
# `test_nested_multierrors`. See
|
||||
# `ai/conc-anal/subint_forkserver_test_cancellation_leak_issue.md`
|
||||
# / #449 for the post-mortem.
|
||||
# @pytest.mark.timeout(
|
||||
# 10,
|
||||
# method='thread',
|
||||
# )
|
||||
@pytest.mark.parametrize(
|
||||
'depth',
|
||||
[1, 3],
|
||||
ids='depth={}'.format,
|
||||
)
|
||||
@tractor_test(
|
||||
# XXX this OUTER `trio.fail_after` wall MUST exceed the
|
||||
# largest INNER `fail_after_w_trace()` budget set in the body
|
||||
# below (max = the MTF depth=3 == 30s case, further scaled by
|
||||
# `cpu_scaling_factor()` on CI/throttle). Otherwise it fires
|
||||
# FIRST and pre-empts the inner snapshot-capturing deadline,
|
||||
# turning a graceful `TooSlowError`+ptree-dump into an opaque
|
||||
# outer timeout-kill (the prior `timeout=10` did exactly this
|
||||
# — it was *smaller* than the 12s trio depth=3 budget, so the
|
||||
# depth-3 case `FAILED` on slow CI instead of dumping).
|
||||
# Trio backend is fast and won't notice the extra budget.
|
||||
# See `ai/conc-anal/cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
timeout=40,
|
||||
)
|
||||
async def test_nested_multierrors(
|
||||
reg_addr: tuple,
|
||||
loglevel: str,
|
||||
start_method: str,
|
||||
set_fork_aware_capture,
|
||||
fail_after_w_trace: FailAfterWTraceFactory,
|
||||
request: pytest.FixtureRequest,
|
||||
depth: int,
|
||||
):
|
||||
'''
|
||||
Test that failed actor sets are wrapped in `BaseExceptionGroup`s. This
|
||||
test goes only 2 nurseries deep but we should eventually have tests
|
||||
for arbitrary n-depth actor trees.
|
||||
Test that failed actor sets are wrapped in `BaseExceptionGroup`s.
|
||||
|
||||
Parametrized over recursion `depth ∈ {1, 3}`:
|
||||
|
||||
- `depth=1`: shallow tree (2 spawners × 2 errorers, 2
|
||||
levels). Cascade completes well within budget on ALL
|
||||
backends including MTF — regression-safety green case.
|
||||
|
||||
- `depth=3`: deep tree (2 spawners × recursive depth-3
|
||||
spawn-and-error). On `main_thread_forkserver` this
|
||||
trips the cancel-cascade shape-mismatch bug class
|
||||
(see `ai/conc-anal/cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`)
|
||||
— xfailed below.
|
||||
|
||||
'''
|
||||
if start_method == 'trio':
|
||||
depth = 3
|
||||
subactor_breadth = 2
|
||||
else:
|
||||
# XXX: multiprocessing can't seem to handle any more then 2 depth
|
||||
# process trees for whatever reason.
|
||||
# Any more process levels then this and we see bugs that cause
|
||||
# hangs and broken pipes all over the place...
|
||||
if start_method == 'forkserver':
|
||||
pytest.skip("Forksever sux hard at nested spawning...")
|
||||
depth = 1 # means an additional actor tree of spawning (2 levels deep)
|
||||
subactor_breadth = 2
|
||||
# XXX: `multiprocessing.forkserver` can't handle nested
|
||||
# spawning at any depth — hangs / broken-pipes. Pre-existing
|
||||
# backend limitation, NOT depth-specific.
|
||||
if start_method == 'forkserver':
|
||||
pytest.skip("Forksever sux hard at nested spawning...")
|
||||
|
||||
with trio.fail_after(120):
|
||||
subactor_breadth = 2
|
||||
|
||||
# MTF backend trips a probabilistic timing race in the
|
||||
# cancel-cascade — NOT depth-gated; depth amplifies the
|
||||
# variance so depth=3 misses nearly every run while
|
||||
# depth=1 misses occasionally. Both get the xfail mark
|
||||
# (with `strict=False`) since the bug class can fire at
|
||||
# either depth.
|
||||
#
|
||||
# The scenario in detail:
|
||||
#
|
||||
# T=0 spawn spawner_0 + spawner_1 in parallel
|
||||
# T=t1 spawner_0's child errors →
|
||||
# RemoteActorError reaches root nursery
|
||||
# T=t1+ε root nursery starts cancelling
|
||||
# spawner_1's portal-wait
|
||||
# T=t2 spawner_1's child errors → tries to send
|
||||
# RemoteActorError back
|
||||
#
|
||||
# if t2 < t1+ε: BEG = [RAE, RAE] ← clean (xpass)
|
||||
# if t2 > t1+ε: BEG = [RAE, Cancelled] ← race tripped (xfail)
|
||||
#
|
||||
# i.e. the assertion below (`isinstance(_, RemoteActorError)`)
|
||||
# fails iff cancel-delivery beats the other tree's natural
|
||||
# error-propagation. Depth amplifies `t2-t1` variance
|
||||
# (longer per-tree paths = more skew); under MTF the
|
||||
# fork-spawn jitter + UDS-contention widens both `t1` and
|
||||
# `t2` further.
|
||||
#
|
||||
# With `strict=False` the clean-cascade cases (most
|
||||
# depth=1 runs, rare depth=3 runs) report as `xpassed`
|
||||
# while the race-tripped cases report as `xfailed` —
|
||||
# neither flakes `--lf`. When MTF cancel-cascade
|
||||
# eventually speeds up enough to close the race even at
|
||||
# depth=3, BOTH variants will reliably `xpass` and
|
||||
# pytest will yell — our signal to drop the marker. See
|
||||
# `ai/conc-anal/cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
#
|
||||
# Probe CPU throttle ONCE up-front (folds in the sustained-load
|
||||
# power-cap that static freq reads miss): used BOTH to inflate
|
||||
# the deadline budget below AND to xfail depth=3, whose failure
|
||||
# mode under throttle is a runtime-internal reap deadline — not
|
||||
# a test-budget miss. See `scripts/cpu-perf-check`.
|
||||
from .conftest import cpu_perf_headroom
|
||||
headroom: float = cpu_perf_headroom()
|
||||
|
||||
if start_method == 'main_thread_forkserver':
|
||||
request.node.add_marker(
|
||||
pytest.mark.xfail(
|
||||
strict=False,
|
||||
reason=(
|
||||
f'MTF cancel-cascade shape-mismatch at '
|
||||
f'depth={depth} (Cancelled races '
|
||||
f'RemoteActorError in BEG); see conc-anal/'
|
||||
'cancel_cascade_too_slow_under_main_thread_forkserver_issue.md'
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# Under CPU throttle (incl. the sustained-load power-cap that
|
||||
# static freq reads miss) the DEEP depth=3 tree trips tractor's
|
||||
# INTERNAL reap deadlines (`soft_kill`/`hard_kill`
|
||||
# `move_on_after`/`terminate_after=1.6`) before slow subprocs
|
||||
# exit, injecting a `Cancelled(source='deadline')` into the BEG
|
||||
# — the SAME shape-mismatch class as the MTF xfail above, and
|
||||
# NOT fixable by inflating the test-level budget (the Cancelled
|
||||
# is minted inside the runtime, not by our `fail_after`).
|
||||
# xfail(strict=False) so it auto-clears the moment the box is
|
||||
# un-throttled (`headroom == 1.`); depth=1's shallow tree stays
|
||||
# under those internal deadlines so it just rides the budget
|
||||
# inflation below. See `scripts/cpu-perf-check`.
|
||||
elif (
|
||||
depth == 3
|
||||
and
|
||||
headroom != 1.
|
||||
):
|
||||
request.node.add_marker(
|
||||
pytest.mark.xfail(
|
||||
strict=False,
|
||||
reason=(
|
||||
'CPU throttled — tractor reap deadline injects '
|
||||
'Cancelled into BEG; see conc-anal/'
|
||||
'trio_033_cancel_cascade_slowdown_depth3_issue.md'
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# Per-backend/-depth budgets: in the non-hang case the
|
||||
# whole spawn + cancel-cascade should complete in well
|
||||
# under these. On the borderline hang case the
|
||||
# `fail_after_w_trace` fires `TooSlowError` AND captures a
|
||||
# ptree/wchan/py-spy snapshot to
|
||||
# `$XDG_CACHE_HOME/tractor/hung-dumps/` for offline
|
||||
# inspection. See
|
||||
# `ai/conc-anal/cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
#
|
||||
# NOTE: the `trio` depth=3 budget was bumped 6 -> 12s after
|
||||
# the `trio` 0.29 -> 0.33 lock bump (commit c7741bba) slowed
|
||||
# the depth-3 cancel-cascade from <6s to ~7-8s; the 6s
|
||||
# deadline was firing and its `Cancelled(source='deadline')`
|
||||
# (trio 0.33 cancel-reason metadata) collapsed a BEG branch,
|
||||
# breaking the `RemoteActorError` assertion below. depth=1
|
||||
# still finishes in ~3s so keeps the 6s budget. See
|
||||
# `ai/conc-anal/trio_033_cancel_cascade_slowdown_depth3_issue.md`.
|
||||
match (start_method, depth):
|
||||
case ('trio', 1):
|
||||
timeout = 6
|
||||
case ('trio', 3):
|
||||
timeout = 12
|
||||
case ('main_thread_forkserver', 1):
|
||||
timeout = 16
|
||||
case ('main_thread_forkserver', 3):
|
||||
timeout = 30
|
||||
|
||||
# inflate the budget by the throttle headroom probed above so
|
||||
# a slow box doesn't masquerade as a deadline regression.
|
||||
# NOTE, `headroom = cpu_perf_headroom()` (set above) is the
|
||||
# SUPERSET of `cpu_scaling_factor()` — it folds in the static
|
||||
# cpu-freq scaling + slow-CI bump AND the sustained-load
|
||||
# throttle probe this depth-3 cascade was the poster child for.
|
||||
if headroom != 1.:
|
||||
timeout *= headroom
|
||||
|
||||
async with fail_after_w_trace(timeout):
|
||||
try:
|
||||
async with tractor.open_nursery() as nursery:
|
||||
for i in range(subactor_breadth):
|
||||
|
|
@ -483,20 +749,24 @@ async def test_nested_multierrors(loglevel, start_method):
|
|||
|
||||
@no_windows
|
||||
def test_cancel_via_SIGINT(
|
||||
loglevel,
|
||||
start_method,
|
||||
spawn_backend,
|
||||
reg_addr: tuple,
|
||||
loglevel: str,
|
||||
start_method: str,
|
||||
):
|
||||
"""Ensure that a control-C (SIGINT) signal cancels both the parent and
|
||||
'''
|
||||
Ensure that a control-C (SIGINT) signal cancels both the parent and
|
||||
child processes in trionic fashion
|
||||
"""
|
||||
|
||||
'''
|
||||
pid: int = os.getpid()
|
||||
|
||||
async def main():
|
||||
with trio.fail_after(2):
|
||||
async with tractor.open_nursery() as tn:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as tn:
|
||||
await tn.start_actor('sucka')
|
||||
if 'mp' in spawn_backend:
|
||||
if 'mp' in start_method:
|
||||
time.sleep(0.1)
|
||||
os.kill(pid, signal.SIGINT)
|
||||
await trio.sleep_forever()
|
||||
|
|
@ -507,6 +777,7 @@ def test_cancel_via_SIGINT(
|
|||
|
||||
@no_windows
|
||||
def test_cancel_via_SIGINT_other_task(
|
||||
reg_addr: tuple,
|
||||
loglevel: str,
|
||||
start_method: str,
|
||||
spawn_backend: str,
|
||||
|
|
@ -517,7 +788,7 @@ def test_cancel_via_SIGINT_other_task(
|
|||
started from a seperate ``trio`` child task.
|
||||
|
||||
'''
|
||||
from .conftest import cpu_scaling_factor
|
||||
from .conftest import cpu_perf_headroom
|
||||
|
||||
pid: int = os.getpid()
|
||||
timeout: float = (
|
||||
|
|
@ -527,15 +798,18 @@ def test_cancel_via_SIGINT_other_task(
|
|||
if _friggin_windows: # smh
|
||||
timeout += 1
|
||||
|
||||
# add latency headroom for CPU freq scaling (auto-cpufreq et al.)
|
||||
headroom: float = cpu_scaling_factor()
|
||||
# latency headroom for static cpu-freq scaling + sustained-load
|
||||
# throttle + CI (auto-cpufreq et al.); see `cpu_perf_headroom()`.
|
||||
headroom: float = cpu_perf_headroom()
|
||||
if headroom != 1.:
|
||||
timeout *= headroom
|
||||
|
||||
async def spawn_and_sleep_forever(
|
||||
task_status=trio.TASK_STATUS_IGNORED
|
||||
):
|
||||
async with tractor.open_nursery() as tn:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as tn:
|
||||
for i in range(3):
|
||||
await tn.run_in_actor(
|
||||
sleep_forever,
|
||||
|
|
@ -599,7 +873,7 @@ async def spawn_sub_with_sync_blocking_task():
|
|||
def test_cancel_while_childs_child_in_sync_sleep(
|
||||
loglevel: str,
|
||||
start_method: str,
|
||||
spawn_backend: str,
|
||||
is_forking_spawner: bool,
|
||||
debug_mode: bool,
|
||||
reg_addr: tuple,
|
||||
man_cancel_outer: bool,
|
||||
|
|
@ -615,7 +889,10 @@ def test_cancel_while_childs_child_in_sync_sleep(
|
|||
|
||||
'''
|
||||
if start_method == 'forkserver':
|
||||
pytest.skip("Forksever sux hard at resuming from sync sleep...")
|
||||
pytest.skip(
|
||||
"`multiprocessing`'s forkserver sux hard at "
|
||||
"resuming from sync sleep..."
|
||||
)
|
||||
|
||||
async def main():
|
||||
#
|
||||
|
|
@ -658,7 +935,11 @@ def test_cancel_while_childs_child_in_sync_sleep(
|
|||
# delay = 2 # is AssertionError in eg AND no TooSlowError !?
|
||||
# is AssertionError in eg AND no _cs cancellation.
|
||||
delay = (
|
||||
6 if _non_linux
|
||||
6 if (
|
||||
_non_linux
|
||||
or
|
||||
is_forking_spawner
|
||||
)
|
||||
else 4
|
||||
)
|
||||
|
||||
|
|
@ -694,7 +975,7 @@ def test_cancel_while_childs_child_in_sync_sleep(
|
|||
|
||||
|
||||
def test_fast_graceful_cancel_when_spawn_task_in_soft_proc_wait_for_daemon(
|
||||
start_method,
|
||||
start_method: str,
|
||||
):
|
||||
'''
|
||||
This is a very subtle test which demonstrates how cancellation
|
||||
|
|
@ -715,6 +996,12 @@ def test_fast_graceful_cancel_when_spawn_task_in_soft_proc_wait_for_daemon(
|
|||
if _friggin_windows: # smh
|
||||
timeout += 1
|
||||
|
||||
# CPU-scaling / sustained-throttle / CI latency headroom — macOS
|
||||
# CI especially is slow for this graceful-vs-hard-reap timing
|
||||
# race; see `cpu_perf_headroom()`.
|
||||
from .conftest import cpu_perf_headroom
|
||||
timeout *= cpu_perf_headroom()
|
||||
|
||||
async def main():
|
||||
start = time.time()
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -24,8 +24,14 @@ def test_empty_mngrs_input_raises(
|
|||
'actor-cluster teardown hangs intermittently on UDS'
|
||||
)
|
||||
|
||||
# inflate under CPU throttle — incl. the sustained-load
|
||||
# power-cap invisible to static freq reads. See
|
||||
# `scripts/cpu-perf-check`.
|
||||
from .conftest import cpu_perf_headroom
|
||||
fail_after_s: float = 3 * cpu_perf_headroom()
|
||||
|
||||
async def main():
|
||||
with trio.fail_after(3):
|
||||
with trio.fail_after(fail_after_s):
|
||||
async with (
|
||||
open_actor_cluster(
|
||||
modules=[__name__],
|
||||
|
|
@ -77,6 +83,7 @@ async def worker(
|
|||
@tractor_test
|
||||
async def test_streaming_to_actor_cluster(
|
||||
tpt_proto: str,
|
||||
is_forking_spawner: bool,
|
||||
):
|
||||
'''
|
||||
Open an actor "cluster" using the (experimental) `._clustering`
|
||||
|
|
@ -88,7 +95,18 @@ async def test_streaming_to_actor_cluster(
|
|||
f'Test currently fails with tpt-proto={tpt_proto!r}\n'
|
||||
)
|
||||
|
||||
with trio.fail_after(6):
|
||||
delay: float = (
|
||||
10 if is_forking_spawner
|
||||
else 6
|
||||
)
|
||||
# inflate under CPU throttle — incl. the sustained-load
|
||||
# power-cap invisible to static freq reads. See
|
||||
# `scripts/cpu-perf-check`.
|
||||
from .conftest import cpu_perf_headroom
|
||||
headroom: float = cpu_perf_headroom()
|
||||
if headroom != 1.:
|
||||
delay *= headroom
|
||||
with trio.fail_after(delay):
|
||||
async with (
|
||||
open_actor_cluster(modules=[__name__]) as portals,
|
||||
|
||||
|
|
|
|||
|
|
@ -115,10 +115,12 @@ async def not_started_but_stream_opened(
|
|||
)
|
||||
def test_started_misuse(
|
||||
target: Callable,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.start_actor(
|
||||
|
|
@ -184,15 +186,24 @@ def test_simple_context(
|
|||
error_parent,
|
||||
child_blocks_forever,
|
||||
pointlessly_open_stream,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
is_forking_spawner: bool,
|
||||
):
|
||||
|
||||
timeout = 1.5 if not platform.system() == 'Windows' else 4
|
||||
timeout: float = 1.5
|
||||
# windows and forking-spawner both have "slower but more
|
||||
# deterministic" cancel teardown.
|
||||
if platform.system() == 'Windows':
|
||||
timeout = 4
|
||||
elif is_forking_spawner:
|
||||
timeout = 3
|
||||
|
||||
async def main():
|
||||
|
||||
with trio.fail_after(timeout):
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.start_actor(
|
||||
|
|
@ -278,6 +289,7 @@ def test_parent_cancels(
|
|||
cancel_method: str,
|
||||
chk_ctx_result_before_exit: bool,
|
||||
child_returns_early: bool,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -355,6 +367,7 @@ def test_parent_cancels(
|
|||
async def main():
|
||||
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.start_actor(
|
||||
|
|
@ -931,6 +944,7 @@ async def keep_sending_from_child(
|
|||
)
|
||||
def test_one_end_stream_not_opened(
|
||||
overrun_by: tuple[str, int, Callable],
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -949,6 +963,7 @@ def test_one_end_stream_not_opened(
|
|||
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.start_actor(
|
||||
|
|
@ -1113,6 +1128,7 @@ def test_maybe_allow_overruns_stream(
|
|||
|
||||
# conftest wide
|
||||
loglevel: str,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -1133,6 +1149,7 @@ def test_maybe_allow_overruns_stream(
|
|||
'''
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.start_actor(
|
||||
|
|
@ -1249,6 +1266,7 @@ def test_maybe_allow_overruns_stream(
|
|||
|
||||
def test_ctx_with_self_actor(
|
||||
loglevel: str,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
):
|
||||
'''
|
||||
|
|
@ -1263,6 +1281,7 @@ def test_ctx_with_self_actor(
|
|||
'''
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
enable_modules=[__name__],
|
||||
) as an:
|
||||
|
|
|
|||
|
|
@ -30,6 +30,32 @@ from tractor import (
|
|||
from tractor.runtime import _state
|
||||
from tractor.trionics import BroadcastReceiver
|
||||
from tractor._testing import expect_ctxc
|
||||
from tractor._testing.trace import (
|
||||
AfkAlarmWTraceFactory,
|
||||
FailAfterWTraceFactory,
|
||||
)
|
||||
|
||||
|
||||
# Per-test zombie-subactor reaper. Opt-in (NOT autouse) —
|
||||
# see `tractor._testing.pytest.reap_subactors_per_test`'s
|
||||
# docstring for the full rationale. This module specifically
|
||||
# needs it because tests like
|
||||
# `test_echoserver_detailed_mechanics[KeyboardInterrupt]`
|
||||
# and the `test_sigint_closes_lifetime_stack[*]` matrix have
|
||||
# been observed to hang past pytest's wall-clock under
|
||||
# `main_thread_forkserver`, leaving subactor forks that
|
||||
# squat on registrar resources and cascade-fail every
|
||||
# subsequent test (`test_inter_peer_cancellation`,
|
||||
# `test_legacy_one_way_streaming`, etc.).
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
'reap_subactors_per_test',
|
||||
# NOTE, asyncio cancel cascade has historically
|
||||
# triggered both UDS sockfile leaks (SIGKILL path)
|
||||
# AND the trio `WakeupSocketpair.drain()` busy-loop
|
||||
# — see `test_aio_simple_error`'s history.
|
||||
'track_orphaned_uds_per_test',
|
||||
'detect_runaway_subactors_per_test',
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
|
|
@ -183,6 +209,7 @@ def test_tractor_cancels_aio(
|
|||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
debug_mode=debug_mode,
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
portal = await an.run_in_actor(
|
||||
asyncio_actor,
|
||||
|
|
@ -205,11 +232,11 @@ def test_trio_cancels_aio(
|
|||
|
||||
'''
|
||||
async def main():
|
||||
|
||||
# cancel the nursery shortly after boot
|
||||
with trio.move_on_after(1):
|
||||
# cancel the nursery shortly after boot
|
||||
|
||||
async with tractor.open_nursery() as tn:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as tn:
|
||||
await tn.run_in_actor(
|
||||
asyncio_actor,
|
||||
target='aio_sleep_forever',
|
||||
|
|
@ -277,7 +304,9 @@ def test_context_spawns_aio_task_that_errors(
|
|||
'''
|
||||
async def main():
|
||||
with trio.fail_after(1 + delay):
|
||||
async with tractor.open_nursery() as an:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
p = await an.start_actor(
|
||||
'aio_daemon',
|
||||
enable_modules=[__name__],
|
||||
|
|
@ -360,7 +389,9 @@ def test_aio_cancelled_from_aio_causes_trio_cancelled(
|
|||
async def main():
|
||||
|
||||
an: tractor.ActorNursery
|
||||
async with tractor.open_nursery() as an:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
p: tractor.Portal = await an.run_in_actor(
|
||||
asyncio_actor,
|
||||
target='aio_cancel',
|
||||
|
|
@ -569,7 +600,9 @@ def test_basic_interloop_channel_stream(
|
|||
async def main():
|
||||
# TODO, figure out min timeout here!
|
||||
with trio.fail_after(6):
|
||||
async with tractor.open_nursery() as an:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
portal = await an.run_in_actor(
|
||||
stream_from_aio,
|
||||
infect_asyncio=True,
|
||||
|
|
@ -582,9 +615,13 @@ def test_basic_interloop_channel_stream(
|
|||
|
||||
|
||||
# TODO: parametrize the above test and avoid the duplication here?
|
||||
def test_trio_error_cancels_intertask_chan(reg_addr):
|
||||
def test_trio_error_cancels_intertask_chan(
|
||||
reg_addr: tuple[str, int],
|
||||
):
|
||||
async def main():
|
||||
async with tractor.open_nursery() as an:
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
portal = await an.run_in_actor(
|
||||
stream_from_aio,
|
||||
trio_raise_err=True,
|
||||
|
|
@ -619,6 +656,7 @@ def test_trio_closes_early_causes_aio_checkpoint_raise(
|
|||
async with tractor.open_nursery(
|
||||
debug_mode=debug_mode,
|
||||
# enable_stack_on_sig=True,
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
portal = await an.run_in_actor(
|
||||
stream_from_aio,
|
||||
|
|
@ -667,6 +705,7 @@ def test_aio_exits_early_relays_AsyncioTaskExited(
|
|||
async def main():
|
||||
with trio.fail_after(1 + delay):
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
# enable_stack_on_sig=True,
|
||||
) as an:
|
||||
|
|
@ -707,6 +746,7 @@ def test_aio_errors_and_channel_propagates_and_closes(
|
|||
):
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
portal = await an.run_in_actor(
|
||||
|
|
@ -796,16 +836,47 @@ async def trio_to_aio_echo_server(
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
'raise_error_mid_stream',
|
||||
[False, Exception, KeyboardInterrupt],
|
||||
[
|
||||
False,
|
||||
Exception,
|
||||
KeyboardInterrupt,
|
||||
],
|
||||
ids='raise_error={}'.format,
|
||||
)
|
||||
def test_echoserver_detailed_mechanics(
|
||||
reg_addr: tuple[str, int],
|
||||
debug_mode: bool,
|
||||
raise_error_mid_stream,
|
||||
|
||||
is_forking_spawner: bool,
|
||||
fail_after_w_trace: FailAfterWTraceFactory,
|
||||
):
|
||||
async def main():
|
||||
# NOTE: under fork-based backends the cancel-cascade
|
||||
# path is structurally slower than `trio`'s subproc-exec
|
||||
# (per-spawn forkserver-handshake compounds during
|
||||
# teardown). Bump the cap so cross-test contamination
|
||||
# doesn't flake this — see
|
||||
# `ai/conc-anal/cancel_cascade_too_slow_under_main_thread_forkserver_issue.md`.
|
||||
timeout: float = (
|
||||
999 if tractor.debug_mode()
|
||||
else 4 if is_forking_spawner
|
||||
# was 1; the `trio` 0.29 -> 0.33 bump slowed the
|
||||
# cancel-cascade so a 1s budget raced the ~1s teardown
|
||||
# deadline. On a deadline-fire the injected
|
||||
# `Cancelled(source='deadline')` wraps the mid-stream
|
||||
# KBI in a `BaseExceptionGroup`, breaking the bare
|
||||
# `pytest.raises(KeyboardInterrupt)` below. See
|
||||
# `ai/conc-anal/trio_033_cancel_cascade_slowdown_depth3_issue.md`.
|
||||
else 4
|
||||
)
|
||||
|
||||
# body factored out so the `fail_after_w_trace`-wrapping
|
||||
# `main()` stays a 2-liner — keeps the deep `open_nursery`
|
||||
# /`open_context`/`open_stream` block at its natural indent
|
||||
# level instead of pushing it under yet another `async with`.
|
||||
async def _body():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
p = await an.start_actor(
|
||||
|
|
@ -849,6 +920,15 @@ def test_echoserver_detailed_mechanics(
|
|||
# is cancelled by kbi or out of task cancellation
|
||||
await p.cancel_actor()
|
||||
|
||||
async def main():
|
||||
# on-timeout diag snapshot via `fail_after_w_trace`
|
||||
# — when the cancel cascade hangs under MTF we get a
|
||||
# fresh `ptree`/`wchan`/`py-spy` dump on disk INSTEAD
|
||||
# of an opaque pytest timeout-kill. See
|
||||
# `tractor/_testing/trace.py`.
|
||||
async with fail_after_w_trace(timeout):
|
||||
await _body()
|
||||
|
||||
if raise_error_mid_stream:
|
||||
with pytest.raises(raise_error_mid_stream):
|
||||
trio.run(main)
|
||||
|
|
@ -984,7 +1064,7 @@ async def manage_file(
|
|||
],
|
||||
ids=[
|
||||
'bg_aio_task',
|
||||
'just_trio_slee',
|
||||
'just_trio_sleep',
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -1000,11 +1080,15 @@ async def manage_file(
|
|||
)
|
||||
def test_sigint_closes_lifetime_stack(
|
||||
tmp_path: Path,
|
||||
reg_addr: tuple,
|
||||
debug_mode: bool,
|
||||
|
||||
wait_for_ctx: bool,
|
||||
bg_aio_task: bool,
|
||||
trio_side_is_shielded: bool,
|
||||
debug_mode: bool,
|
||||
send_sigint_to: str,
|
||||
is_forking_spawner: bool,
|
||||
afk_alarm_w_trace: AfkAlarmWTraceFactory,
|
||||
):
|
||||
'''
|
||||
Ensure that an infected child can use the `Actor.lifetime_stack`
|
||||
|
|
@ -1014,12 +1098,30 @@ def test_sigint_closes_lifetime_stack(
|
|||
'''
|
||||
async def main():
|
||||
|
||||
delay = 999 if tractor.debug_mode() else 1
|
||||
delay: float = (
|
||||
999
|
||||
if debug_mode
|
||||
else 1
|
||||
)
|
||||
# pre-init so the `except (KeyboardInterrupt, ContextCancelled)`
|
||||
# handler below doesn't `UnboundLocalError` if KBI fires BEFORE
|
||||
# we ever enter the `as (ctx, first)` body (e.g. when
|
||||
# `p.open_context().__aenter__` is hung waiting for the
|
||||
# subactor's `StartAck` due to a fork-child IPC race —
|
||||
# see `dynamic_pub_sub_spawn_time_transport_close_under_mtf_issue.md`).
|
||||
tmp_file: Path|None = None
|
||||
ctx: tractor.Context|None = None
|
||||
try:
|
||||
an: tractor.ActorNursery
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
|
||||
# sanity
|
||||
if debug_mode:
|
||||
assert tractor.debug_mode()
|
||||
|
||||
p: tractor.Portal = await an.start_actor(
|
||||
'file_mngr',
|
||||
enable_modules=[__name__],
|
||||
|
|
@ -1034,7 +1136,7 @@ def test_sigint_closes_lifetime_stack(
|
|||
) as (ctx, first):
|
||||
|
||||
path_str, cpid = first
|
||||
tmp_file: Path = Path(path_str)
|
||||
tmp_file = Path(path_str)
|
||||
assert tmp_file.exists()
|
||||
|
||||
# XXX originally to simulate what (hopefully)
|
||||
|
|
@ -1054,6 +1156,10 @@ def test_sigint_closes_lifetime_stack(
|
|||
cpid if send_sigint_to == 'child'
|
||||
else os.getpid()
|
||||
)
|
||||
print(
|
||||
f'Sending SIGINT to {send_sigint_to!r}\n'
|
||||
f'pid: {pid!r}\n'
|
||||
)
|
||||
os.kill(
|
||||
pid,
|
||||
signal.SIGINT,
|
||||
|
|
@ -1064,13 +1170,37 @@ def test_sigint_closes_lifetime_stack(
|
|||
# timeout should trigger!
|
||||
if wait_for_ctx:
|
||||
print('waiting for ctx outcome in parent..')
|
||||
|
||||
if debug_mode:
|
||||
assert delay == 999
|
||||
|
||||
try:
|
||||
with trio.fail_after(1 + delay):
|
||||
with trio.fail_after(
|
||||
1 + delay
|
||||
):
|
||||
await ctx.wait_for_result()
|
||||
except tractor.ContextCancelled as ctxc:
|
||||
assert ctxc.canceller == ctx.chan.uid
|
||||
raise
|
||||
|
||||
except trio.TooSlowError:
|
||||
if (
|
||||
send_sigint_to == 'child'
|
||||
and
|
||||
is_forking_spawner
|
||||
):
|
||||
pytest.xfail(
|
||||
reason=(
|
||||
'SIGINT delivery to fork-child subactor is known '
|
||||
'to NOT SUCCEED, precisely bc we have not wired up a'
|
||||
'"trio SIGINT mode" in the child pre-fork.\n'
|
||||
'Also see `test_orphaned_subactor_sigint_cleanup_DRAFT` for'
|
||||
'a dedicated suite demonstrating this expected limitation as '
|
||||
'well as the detailed doc:\n'
|
||||
'`ai/conc-anal/subint_forkserver_orphan_sigint_hang_issue.md`.\n'
|
||||
),
|
||||
)
|
||||
|
||||
# XXX CASE 2: this seems to be the source of the
|
||||
# original issue which exhibited BEFORE we put
|
||||
# a `Actor.cancel_soon()` inside
|
||||
|
|
@ -1084,6 +1214,21 @@ def test_sigint_closes_lifetime_stack(
|
|||
KeyboardInterrupt,
|
||||
ContextCancelled,
|
||||
):
|
||||
# If we got here BEFORE entering the ctx body (e.g.
|
||||
# spawn-time IPC race hung `open_context.__aenter__` and
|
||||
# the AFK-guard `signal.alarm` fired KBI from outside the
|
||||
# trio loop), `tmp_file`/`ctx` are still `None` — surface
|
||||
# that fact directly instead of `UnboundLocalError`.
|
||||
if tmp_file is None:
|
||||
pytest.fail(
|
||||
'KBI/ctxc fired BEFORE `p.open_context()` returned '
|
||||
"the child's `started` value — likely fork-child "
|
||||
'IPC race; see '
|
||||
'`ai/conc-anal/'
|
||||
'dynamic_pub_sub_spawn_time_transport_close_'
|
||||
'under_mtf_issue.md`'
|
||||
)
|
||||
|
||||
# XXX CASE 2: without the bug fixed, in the
|
||||
# KBI-raised-in-parent case, the actor teardown should
|
||||
# never get run (silently abaondoned by `asyncio`..) and
|
||||
|
|
@ -1091,7 +1236,26 @@ def test_sigint_closes_lifetime_stack(
|
|||
assert not tmp_file.exists()
|
||||
assert ctx.maybe_error
|
||||
|
||||
trio.run(main)
|
||||
# outer hard wall-clock backstop via `afk_alarm_w_trace`:
|
||||
# when the in-band trio cancel path doesn't fire (e.g.
|
||||
# parent is parked in a shielded `await` inside actor-
|
||||
# nursery teardown, or `open_context.__aenter__` hangs
|
||||
# waiting for a child's `StartAck` that never comes), the
|
||||
# `signal.alarm` inside the CM raises `AFKAlarmTimeout`
|
||||
# in the main thread regardless of trio's scope state —
|
||||
# AND captures a full diag snapshot to
|
||||
# `$XDG_CACHE_HOME/tractor/hung-dumps/` before re-raising.
|
||||
# Only armed under fork-based backends since this hang-
|
||||
# class is MTF-specific.
|
||||
if (
|
||||
not debug_mode
|
||||
and
|
||||
is_forking_spawner
|
||||
):
|
||||
with afk_alarm_w_trace(10):
|
||||
trio.run(main)
|
||||
else:
|
||||
trio.run(main)
|
||||
|
||||
|
||||
|
||||
|
|
@ -1170,6 +1334,7 @@ def test_aio_side_raises_before_started(
|
|||
with trio.fail_after(3):
|
||||
an: tractor.ActorNursery
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
debug_mode=debug_mode,
|
||||
loglevel=loglevel,
|
||||
) as an:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,31 @@ from tractor._testing import (
|
|||
|
||||
from .conftest import cpu_scaling_factor
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.skipon_spawn_backend(
|
||||
'subint',
|
||||
reason=(
|
||||
'XXX SUBINT GIL-CONTENTION HANGING TEST XXX\n'
|
||||
'Inter-peer cancel cascades under '
|
||||
'`--spawn-backend=subint` trip the abandoned-subint '
|
||||
'GIL-hostage class — see\n'
|
||||
' - `ai/conc-anal/subint_sigint_starvation_issue.md` '
|
||||
'(GIL-hostage, SIGINT-unresponsive)\n'
|
||||
' - `ai/conc-anal/subint_cancel_delivery_hang_issue.md` '
|
||||
'(sibling: parent parks on dead chan)\n'
|
||||
' - https://github.com/goodboy/tractor/issues/379 '
|
||||
'(subint umbrella)\n'
|
||||
)
|
||||
),
|
||||
# NOTE, inter-peer cancellation tests stress the
|
||||
# multi-actor cancel cascade which under SIGKILL
|
||||
# leaves UDS sock-files orphaned. Track per-test
|
||||
# for blame attribution.
|
||||
pytest.mark.usefixtures(
|
||||
'track_orphaned_uds_per_test',
|
||||
),
|
||||
]
|
||||
|
||||
# XXX TODO cases:
|
||||
# - [x] WE cancelled the peer and thus should not see any raised
|
||||
# `ContextCancelled` as it should be reaped silently?
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
'''
|
||||
Streaming via the, now legacy, "async-gen API".
|
||||
|
||||
"""
|
||||
'''
|
||||
import time
|
||||
from functools import partial
|
||||
import platform
|
||||
|
|
@ -12,6 +12,11 @@ import tractor
|
|||
import pytest
|
||||
|
||||
from tractor._testing import tractor_test
|
||||
from tractor._exceptions import ActorTooSlowError
|
||||
|
||||
_non_linux: bool = (
|
||||
_sys := platform.system()
|
||||
) != 'Linux'
|
||||
|
||||
|
||||
def test_must_define_ctx():
|
||||
|
|
@ -68,8 +73,10 @@ async def stream_from_single_subactor(
|
|||
start_method,
|
||||
stream_func,
|
||||
):
|
||||
"""Verify we can spawn a daemon actor and retrieve streamed data.
|
||||
"""
|
||||
'''
|
||||
Verify we can spawn a daemon actor and retrieve streamed data.
|
||||
|
||||
'''
|
||||
# only one per host address, spawns an actor if None
|
||||
|
||||
async with tractor.open_nursery(
|
||||
|
|
@ -242,14 +249,19 @@ async def a_quadruple_example() -> list[int]:
|
|||
start = time.time()
|
||||
# the portal call returns exactly what you'd expect
|
||||
# as if the remote "aggregate" function was called locally
|
||||
result_stream = []
|
||||
result_stream: list[int] = []
|
||||
|
||||
async with portal.open_stream_from(aggregate, seed=seed) as stream:
|
||||
async with portal.open_stream_from(
|
||||
aggregate,
|
||||
seed=seed,
|
||||
) as stream:
|
||||
async for value in stream:
|
||||
result_stream.append(value)
|
||||
|
||||
print(f"STREAM TIME = {time.time() - start}")
|
||||
print(f"STREAM + SPAWN TIME = {time.time() - pre_start}")
|
||||
print(
|
||||
f"STREAM TIME = {time.time() - start}\n"
|
||||
f"STREAM + SPAWN TIME = {time.time() - pre_start}\n"
|
||||
)
|
||||
assert result_stream == list(range(seed))
|
||||
await portal.cancel_actor()
|
||||
return result_stream
|
||||
|
|
@ -258,13 +270,24 @@ async def a_quadruple_example() -> list[int]:
|
|||
async def cancel_after(
|
||||
wait: float,
|
||||
reg_addr: tuple,
|
||||
expect_cancel: bool,
|
||||
) -> list[int]:
|
||||
|
||||
async with tractor.open_root_actor(
|
||||
registry_addrs=[reg_addr],
|
||||
):
|
||||
with trio.move_on_after(wait):
|
||||
return await a_quadruple_example()
|
||||
res: list[int]|None = None
|
||||
with trio.move_on_after(wait) as cs:
|
||||
res: list[int] = await a_quadruple_example()
|
||||
return res
|
||||
|
||||
if (
|
||||
not expect_cancel
|
||||
and
|
||||
cs.cancelled_caught
|
||||
):
|
||||
assert not res
|
||||
raise ActorTooSlowError
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
|
|
@ -272,9 +295,14 @@ def time_quad_ex(
|
|||
reg_addr: tuple,
|
||||
ci_env: bool,
|
||||
spawn_backend: str,
|
||||
is_forking_spawner: bool,
|
||||
tpt_proto: str,
|
||||
):
|
||||
non_linux: bool = (_sys := platform.system()) != 'Linux'
|
||||
if ci_env and non_linux:
|
||||
if (
|
||||
ci_env
|
||||
and
|
||||
_non_linux
|
||||
):
|
||||
pytest.skip(f'Test is too flaky on {_sys!r} in CI')
|
||||
|
||||
if spawn_backend == 'mp':
|
||||
|
|
@ -284,15 +312,42 @@ def time_quad_ex(
|
|||
'''
|
||||
pytest.skip("Test is too flaky on mp in CI")
|
||||
|
||||
timeout = 7 if non_linux else 4
|
||||
start = time.time()
|
||||
results: list[int] = trio.run(
|
||||
cancel_after,
|
||||
timeout,
|
||||
reg_addr,
|
||||
timeout: float = (
|
||||
7 if _non_linux
|
||||
else 4
|
||||
)
|
||||
|
||||
if (
|
||||
is_forking_spawner
|
||||
and
|
||||
tpt_proto in [
|
||||
'uds',
|
||||
]
|
||||
):
|
||||
timeout += 1
|
||||
|
||||
# inflate the cancel-deadline for static cpu-freq scaling +
|
||||
# sustained-load throttle + CI latency (see `cpu_perf_headroom()`)
|
||||
# so the example isn't cancelled mid-stream on a throttled/CI box.
|
||||
from .conftest import cpu_perf_headroom
|
||||
timeout *= cpu_perf_headroom()
|
||||
|
||||
start: float = time.time()
|
||||
results: list[int] = trio.run(partial(
|
||||
cancel_after,
|
||||
wait=timeout,
|
||||
reg_addr=reg_addr,
|
||||
expect_cancel=True,
|
||||
))
|
||||
diff: float = time.time() - start
|
||||
assert results
|
||||
if results is None:
|
||||
raise ActorTooSlowError(
|
||||
f'Streaming example took longer then timeout ??\n'
|
||||
f'timeout={timeout!r}\n'
|
||||
f'diff={diff!r}\n'
|
||||
f'results={results!r}\n'
|
||||
)
|
||||
|
||||
return results, diff
|
||||
|
||||
|
||||
|
|
@ -307,11 +362,10 @@ def test_a_quadruple_example(
|
|||
given past empirical eval of this suite.
|
||||
|
||||
'''
|
||||
non_linux: bool = (_sys := platform.system()) != 'Linux'
|
||||
|
||||
this_fast_on_linux: float = 3
|
||||
this_fast = (
|
||||
6 if non_linux
|
||||
6 if _non_linux
|
||||
else this_fast_on_linux
|
||||
)
|
||||
# ^ XXX NOTE,
|
||||
|
|
@ -325,8 +379,8 @@ def test_a_quadruple_example(
|
|||
# https://github.com/AdnanHodzic/auto-cpufreq?tab=readme-ov-file#example-config-file-contents
|
||||
#
|
||||
# HENCE this below latency-headroom compensation logic..
|
||||
from .conftest import cpu_scaling_factor
|
||||
headroom: float = cpu_scaling_factor()
|
||||
from .conftest import cpu_perf_headroom
|
||||
headroom: float = cpu_perf_headroom()
|
||||
if headroom != 1.:
|
||||
this_fast = this_fast_on_linux * headroom
|
||||
test_log.warning(
|
||||
|
|
@ -348,21 +402,26 @@ def test_not_fast_enough_quad(
|
|||
reg_addr: tuple,
|
||||
time_quad_ex: tuple[list[int], float],
|
||||
cancel_delay: float,
|
||||
|
||||
ci_env: bool,
|
||||
spawn_backend: str,
|
||||
is_forking_spawner: bool,
|
||||
tpt_proto: str,
|
||||
test_log: tractor.log.StackLevelAdapter,
|
||||
):
|
||||
'''
|
||||
Verify we can cancel midway through the quad example and all
|
||||
actors cancel gracefully.
|
||||
Verify we can cancel midway through `a_quadruple_example()`, at
|
||||
various delays, and all subactors cancel gracefully.
|
||||
|
||||
'''
|
||||
results, diff = time_quad_ex
|
||||
delay = max(diff - cancel_delay, 0)
|
||||
results = trio.run(
|
||||
results: list[int] = trio.run(partial(
|
||||
cancel_after,
|
||||
delay,
|
||||
reg_addr,
|
||||
)
|
||||
wait=delay,
|
||||
reg_addr=reg_addr,
|
||||
expect_cancel=True,
|
||||
))
|
||||
system: str = platform.system()
|
||||
if (
|
||||
system in ('Windows', 'Darwin')
|
||||
|
|
@ -373,6 +432,20 @@ def test_not_fast_enough_quad(
|
|||
# so just ignore these
|
||||
print(f'Woa there {system} caught your breath eh?')
|
||||
else:
|
||||
if (
|
||||
results
|
||||
and
|
||||
is_forking_spawner
|
||||
and
|
||||
tpt_proto in [
|
||||
'uds',
|
||||
]
|
||||
):
|
||||
pytest.xfail(
|
||||
f'Spawning backend + tpt-proto is too fast XD\n'
|
||||
f'{spawn_backend!r} + {tpt_proto!r}\n'
|
||||
)
|
||||
|
||||
# should be cancelled mid-streaming
|
||||
assert results is None
|
||||
|
||||
|
|
|
|||
|
|
@ -10,18 +10,22 @@ import tractor
|
|||
from tractor._testing import tractor_test
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_no_runtime():
|
||||
"""A registrar must be established before any nurseries
|
||||
def test_no_runtime():
|
||||
'''
|
||||
A registrar must be established before any nurseries
|
||||
can be created.
|
||||
|
||||
(In other words ``tractor.open_root_actor()`` must be
|
||||
engaged at some point?)
|
||||
"""
|
||||
with pytest.raises(RuntimeError) :
|
||||
|
||||
'''
|
||||
async def main():
|
||||
async with tractor.find_actor('doggy'):
|
||||
pass
|
||||
|
||||
with pytest.raises(tractor._exceptions.NoRuntime):
|
||||
trio.run(main)
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_self_is_registered(reg_addr):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,16 @@ def test_root_pkg_not_duplicated_in_logger_name():
|
|||
a common `<root_name>.< >` prefix, ensure that it is not
|
||||
duplicated in the child's `StackLevelAdapter.name: str`.
|
||||
|
||||
Also pins the explicit-`name` contract: an explicitly passed
|
||||
dotted `name` is treated as a *literal* sub-logger path and is
|
||||
NOT leaf-collapsed. The leaf-module is only dropped when the
|
||||
trailing token duplicates the *caller's own* `__name__` leaf (the
|
||||
`{filename}` field) — see `test_implicit_mod_name_applied_for_child`
|
||||
for that (auto-naming) path. This is what keeps a real (possibly
|
||||
nested) sub-PACKAGE like `subpkg.mod` -> `devx.debug` addressable
|
||||
by the `tractor.log` logging-spec, instead of collapsing to its
|
||||
parent.
|
||||
|
||||
'''
|
||||
project_name: str = 'pylib'
|
||||
pkg_path: str = 'pylib.subpkg.mod'
|
||||
|
|
@ -38,8 +48,13 @@ def test_root_pkg_not_duplicated_in_logger_name():
|
|||
)
|
||||
|
||||
assert proj_log is not sublog
|
||||
# the root pkg-name appears exactly once (no `pylib.pylib...`)
|
||||
assert sublog.name.count(proj_log.name) == 1
|
||||
assert 'mod' not in sublog.name
|
||||
# explicit dotted `name` is preserved literally (NOT collapsed);
|
||||
# the trailing token survives since it's not the *caller's* own
|
||||
# leaf-module (`test_log_sys`), so this is treated as a literal
|
||||
# sub-pkg path.
|
||||
assert sublog.name == f'{project_name}.subpkg.mod'
|
||||
|
||||
|
||||
def test_implicit_mod_name_applied_for_child(
|
||||
|
|
@ -147,6 +162,66 @@ def test_implicit_mod_name_applied_for_child(
|
|||
assert submod.log.logger in sub_logs
|
||||
|
||||
|
||||
def test_io_custom_level_registered():
|
||||
'''
|
||||
The `IO`(21) level (registered via `add_log_level()` at
|
||||
import, for `tractor.trionics._subproc`'s std-stream relay)
|
||||
is fully wired and SHOWN BY DEFAULT at `info`-level consoles
|
||||
since `21 >= INFO(20)`.
|
||||
|
||||
'''
|
||||
import logging
|
||||
assert log.CUSTOM_LEVELS.get('IO') == 21
|
||||
assert logging.getLevelName(21) == 'IO'
|
||||
assert log.STD_PALETTE.get('IO')
|
||||
assert log.BOLD_PALETTE['bold'].get('IO')
|
||||
|
||||
iolog = log.get_logger('io_lvl_test')
|
||||
assert callable(getattr(iolog, 'io', None))
|
||||
# emit must not raise
|
||||
iolog.io('hello from the IO level')
|
||||
|
||||
# 21 >= INFO(20) -> shown when console set to `info`
|
||||
assert 21 >= logging.INFO
|
||||
|
||||
|
||||
def test_add_log_level_pluggable():
|
||||
'''
|
||||
`add_log_level()` is the single pluggable entry-point: one
|
||||
call wires `CUSTOM_LEVELS` + `addLevelName` + both palettes +
|
||||
a same-named `StackLevelAdapter` emit method (so
|
||||
`get_logger()`'s per-level audit passes).
|
||||
|
||||
'''
|
||||
import logging
|
||||
name: str = 'XLVL'
|
||||
val: int = 19
|
||||
try:
|
||||
log.add_log_level(name, val, 'cyan')
|
||||
|
||||
assert log.CUSTOM_LEVELS[name] == val
|
||||
assert logging.getLevelName(val) == name
|
||||
assert log.STD_PALETTE[name] == 'cyan'
|
||||
assert log.BOLD_PALETTE['bold'][name] == 'bold_cyan'
|
||||
|
||||
# the audit in `get_logger()` (asserts a method per
|
||||
# `CUSTOM_LEVELS` entry) must still pass.
|
||||
xlog = log.get_logger('xlvl_test')
|
||||
emit = getattr(xlog, name.lower(), None)
|
||||
assert callable(emit)
|
||||
emit('hello from a plugged-in level')
|
||||
|
||||
finally:
|
||||
# best-effort cleanup of our module-global mutations so
|
||||
# later `get_logger()` audits don't see a half-removed
|
||||
# level.
|
||||
log.CUSTOM_LEVELS.pop(name, None)
|
||||
log.STD_PALETTE.pop(name, None)
|
||||
log.BOLD_PALETTE['bold'].pop(name, None)
|
||||
if hasattr(log.StackLevelAdapter, name.lower()):
|
||||
delattr(log.StackLevelAdapter, name.lower())
|
||||
|
||||
|
||||
# TODO, moar tests against existing feats:
|
||||
# ------ - ------
|
||||
# - [ ] color settings?
|
||||
|
|
|
|||
|
|
@ -1,183 +0,0 @@
|
|||
"""
|
||||
Multiple python programs invoking the runtime.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import platform
|
||||
import subprocess
|
||||
import time
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
import tractor
|
||||
from tractor._testing import (
|
||||
tractor_test,
|
||||
)
|
||||
from tractor import (
|
||||
current_actor,
|
||||
Actor,
|
||||
Context,
|
||||
Portal,
|
||||
)
|
||||
from tractor.runtime import _state
|
||||
from .conftest import (
|
||||
sig_prog,
|
||||
_INT_SIGNAL,
|
||||
_INT_RETURN_CODE,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from tractor.msg import Aid
|
||||
from tractor.discovery._addr import (
|
||||
UnwrappedAddress,
|
||||
)
|
||||
|
||||
|
||||
_non_linux: bool = platform.system() != 'Linux'
|
||||
|
||||
|
||||
def test_abort_on_sigint(
|
||||
daemon: subprocess.Popen,
|
||||
):
|
||||
assert daemon.returncode is None
|
||||
time.sleep(0.1)
|
||||
sig_prog(daemon, _INT_SIGNAL)
|
||||
assert daemon.returncode == _INT_RETURN_CODE
|
||||
|
||||
# XXX: oddly, couldn't get capfd.readouterr() to work here?
|
||||
if platform.system() != 'Windows':
|
||||
# don't check stderr on windows as its empty when sending CTRL_C_EVENT
|
||||
assert "KeyboardInterrupt" in str(daemon.stderr.read())
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_cancel_remote_registrar(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
):
|
||||
assert not current_actor().is_registrar
|
||||
async with tractor.get_registry(reg_addr) as portal:
|
||||
await portal.cancel_actor()
|
||||
|
||||
time.sleep(0.1)
|
||||
# the registrar channel server is cancelled but not its main task
|
||||
assert daemon.returncode is None
|
||||
|
||||
# no registrar socket should exist
|
||||
with pytest.raises(OSError):
|
||||
async with tractor.get_registry(reg_addr) as portal:
|
||||
pass
|
||||
|
||||
|
||||
def test_register_duplicate_name(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
):
|
||||
async def main():
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
) as an:
|
||||
|
||||
assert not current_actor().is_registrar
|
||||
|
||||
p1 = await an.start_actor('doggy')
|
||||
p2 = await an.start_actor('doggy')
|
||||
|
||||
async with tractor.wait_for_actor('doggy') as portal:
|
||||
assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)
|
||||
|
||||
await an.cancel()
|
||||
|
||||
# XXX, run manually since we want to start this root **after**
|
||||
# the other "daemon" program with it's own root.
|
||||
trio.run(main)
|
||||
|
||||
|
||||
@tractor.context
|
||||
async def get_root_portal(
|
||||
ctx: Context,
|
||||
):
|
||||
'''
|
||||
Connect back to the root actor manually (using `._discovery` API)
|
||||
and ensure it's contact info is the same as our immediate parent.
|
||||
|
||||
'''
|
||||
sub: Actor = current_actor()
|
||||
rtvs: dict = _state._runtime_vars
|
||||
raddrs: list[UnwrappedAddress] = rtvs['_root_addrs']
|
||||
|
||||
# await tractor.pause()
|
||||
# XXX, in case the sub->root discovery breaks you might need
|
||||
# this (i know i did Xp)!!
|
||||
# from tractor.devx import mk_pdb
|
||||
# mk_pdb().set_trace()
|
||||
|
||||
assert (
|
||||
len(raddrs) == 1
|
||||
and
|
||||
list(sub._parent_chan.raddr.unwrap()) in raddrs
|
||||
)
|
||||
|
||||
# connect back to our immediate parent which should also
|
||||
# be the actor-tree's root.
|
||||
from tractor.discovery._api import get_root
|
||||
ptl: Portal
|
||||
async with get_root() as ptl:
|
||||
root_aid: Aid = ptl.chan.aid
|
||||
parent_ptl: Portal = current_actor().get_parent()
|
||||
assert (
|
||||
root_aid.name == 'root'
|
||||
and
|
||||
parent_ptl.chan.aid == root_aid
|
||||
)
|
||||
await ctx.started()
|
||||
|
||||
|
||||
def test_non_registrar_spawns_child(
|
||||
daemon: subprocess.Popen,
|
||||
reg_addr: UnwrappedAddress,
|
||||
loglevel: str,
|
||||
debug_mode: bool,
|
||||
ci_env: bool,
|
||||
):
|
||||
'''
|
||||
Ensure a non-regristar (serving) root actor can spawn a sub and
|
||||
that sub can connect back (manually) to it's rent that is the
|
||||
root without issue.
|
||||
|
||||
More or less this audits the global contact info in
|
||||
`._state._runtime_vars`.
|
||||
|
||||
'''
|
||||
async def main():
|
||||
|
||||
# XXX, since apparently on macos in GH's CI it can be a race
|
||||
# with the `daemon` registrar on grabbing the socket-addr..
|
||||
if ci_env and _non_linux:
|
||||
await trio.sleep(.5)
|
||||
|
||||
async with tractor.open_nursery(
|
||||
registry_addrs=[reg_addr],
|
||||
loglevel=loglevel,
|
||||
debug_mode=debug_mode,
|
||||
) as an:
|
||||
|
||||
actor: Actor = tractor.current_actor()
|
||||
assert not actor.is_registrar
|
||||
sub_ptl: Portal = await an.start_actor(
|
||||
name='sub',
|
||||
enable_modules=[__name__],
|
||||
)
|
||||
|
||||
async with sub_ptl.open_context(
|
||||
get_root_portal,
|
||||
) as (ctx, _):
|
||||
print('Waiting for `sub` to connect back to us..')
|
||||
|
||||
await an.cancel()
|
||||
|
||||
# XXX, run manually since we want to start this root **after**
|
||||
# the other "daemon" program with it's own root.
|
||||
trio.run(main)
|
||||
|
|
@ -7,6 +7,14 @@ import tractor
|
|||
from tractor.experimental import msgpub
|
||||
from tractor._testing import tractor_test
|
||||
|
||||
pytestmark = pytest.mark.skipon_spawn_backend(
|
||||
'subint',
|
||||
reason=(
|
||||
'XXX SUBINT HANGING TEST XXX\n'
|
||||
'See oustanding issue(s)\n'
|
||||
# TODO, put issue link!
|
||||
)
|
||||
)
|
||||
|
||||
def test_type_checks():
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ import trio
|
|||
import pytest
|
||||
|
||||
import tractor
|
||||
|
||||
# XXX `cffi` dun build on py3.14 yet..
|
||||
pytest.importorskip("cffi")
|
||||
|
||||
from tractor.ipc._ringbuf import (
|
||||
open_ringbuf,
|
||||
RBToken,
|
||||
|
|
@ -14,9 +18,12 @@ from tractor._testing.samples import (
|
|||
generate_sample_messages,
|
||||
)
|
||||
|
||||
# in case you don't want to melt your cores, uncomment dis!
|
||||
# XXX, in case you want to melt your cores, comment this skip line XD
|
||||
pytestmark = pytest.mark.skip
|
||||
|
||||
# XXX `cffi` dun build on py3.14 yet..
|
||||
cffi = pytest.importorskip("cffi")
|
||||
|
||||
|
||||
@tractor.context
|
||||
async def child_read_shm(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,20 @@ from tractor.ipc._shm import (
|
|||
attach_shm_list,
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.skipon_spawn_backend(
|
||||
'subint',
|
||||
# NOTE, `main_thread_forkserver` works for these tests
|
||||
# via the `mp.SharedMemory(track=False)` +
|
||||
# `mp.resource_tracker` monkey-patch in `.ipc._mp_bs`.
|
||||
# Without that workaround the fork-inherited
|
||||
# `resource_tracker` fd would EBADF on first shm op +
|
||||
# cascade into `FileExistsError` across parametrize
|
||||
# variants. Tracker doc:
|
||||
# `ai/conc-anal/subint_forkserver_mp_shared_memory_issue.md`.
|
||||
reason=(
|
||||
'subint: GIL-contention hanging class.\n'
|
||||
)
|
||||
)
|
||||
|
||||
@tractor.context
|
||||
async def child_attach_shml_alot(
|
||||
|
|
|
|||
|
|
@ -194,9 +194,14 @@ def test_loglevel_propagated_to_subactor(
|
|||
reg_addr: tuple,
|
||||
level: str,
|
||||
):
|
||||
if start_method == 'mp_forkserver':
|
||||
if start_method in ('mp_forkserver', 'main_thread_forkserver'):
|
||||
pytest.skip(
|
||||
"a bug with `capfd` seems to make forkserver capture not work?"
|
||||
"a bug with `capfd` seems to make forkserver capture not work? "
|
||||
"(same class as the `mp_forkserver` pre-existing skip — fork-"
|
||||
"based backends inherit pytest's capfd temp-file fds into the "
|
||||
"subactor and the IPC handshake reads garbage (`unclean EOF "
|
||||
"read only X/HUGE_NUMBER bytes`). Work around by using "
|
||||
"`capsys` instead or skip entirely."
|
||||
)
|
||||
|
||||
async def main():
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
'''
|
||||
Regression tests for `tractor.trionics.patches` —
|
||||
defensive monkey-patches on upstream `trio` bugs.
|
||||
|
||||
Each test asserts:
|
||||
|
||||
1. The bug exists (or is gone — skip cleanly if
|
||||
upstream shipped the fix and our `is_needed()` now
|
||||
returns `False`).
|
||||
2. Our patch fixes it (post-`apply()` the `repro()`
|
||||
returns cleanly within a tight wall-clock cap).
|
||||
|
||||
Wall-clock caps are critical here — the bugs we patch
|
||||
are tight-loops or deadlocks, so a regression would
|
||||
HANG the test runner unless we hard-cap each
|
||||
`repro()` call.
|
||||
|
||||
'''
|
||||
import signal
|
||||
|
||||
import pytest
|
||||
|
||||
from tractor.trionics import patches
|
||||
from tractor.trionics.patches import _wakeup_socketpair as wsp
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _alarm_cleanup():
|
||||
'''
|
||||
Ensure no leftover SIGALRM survives a test failure
|
||||
or unexpected return.
|
||||
|
||||
'''
|
||||
yield
|
||||
signal.alarm(0)
|
||||
|
||||
|
||||
def test_wakeup_socketpair_drain_eof_patch_works():
|
||||
'''
|
||||
Without the patch, `WakeupSocketpair.drain()` on a
|
||||
socketpair whose write-end has been closed spins
|
||||
forever. With the patch applied, it returns
|
||||
cleanly within milliseconds.
|
||||
|
||||
Wall-clock cap: 2s. If the patch regresses, SIGALRM
|
||||
fires and the test hard-fails with a clear signal
|
||||
instead of hanging CI indefinitely.
|
||||
|
||||
'''
|
||||
if not wsp.is_needed():
|
||||
pytest.skip(
|
||||
'upstream trio shipped the fix — '
|
||||
'patch no longer needed for trio '
|
||||
'(see `is_needed()` for version gate)'
|
||||
)
|
||||
|
||||
# Apply the patch.
|
||||
applied: bool = wsp.apply()
|
||||
# First call MUST return True; idempotent guard
|
||||
# prevents False on subsequent calls within the
|
||||
# same process.
|
||||
assert isinstance(applied, bool) # idempotent (order-dependent value)
|
||||
|
||||
# Cap wall-clock at 2s; SIGALRM raises in main
|
||||
# thread which interrupts the C-level recv loop
|
||||
# IF the patch regresses (since `signal.alarm`
|
||||
# uses Python's signal-wakeup-fd which the patch
|
||||
# itself relies on... but `repro()` runs OUTSIDE
|
||||
# a trio.run, so it's plain stdlib semantics here
|
||||
# — alarm WILL fire during `recv` syscall).
|
||||
signal.alarm(2)
|
||||
wsp.repro()
|
||||
signal.alarm(0)
|
||||
|
||||
|
||||
def test_apply_all_idempotent():
|
||||
'''
|
||||
Calling `apply_all()` twice should not double-
|
||||
apply: second call's dict has all-False values
|
||||
(every patch reports "already applied").
|
||||
|
||||
'''
|
||||
first: dict[str, bool] = patches.apply_all()
|
||||
second: dict[str, bool] = patches.apply_all()
|
||||
|
||||
# Second call: every patch reports skipped.
|
||||
assert all(v is False for v in second.values()), (
|
||||
f'apply_all() not idempotent: {second}'
|
||||
)
|
||||
|
||||
# First call: at least one patch was applied
|
||||
# (or all are no-ops because `is_needed()` is
|
||||
# False everywhere — the all-fixed-upstream future
|
||||
# state which is also valid).
|
||||
assert isinstance(first, dict)
|
||||
for name, applied in first.items():
|
||||
assert isinstance(applied, bool), (
|
||||
f'patch {name!r} returned non-bool: {applied!r}'
|
||||
)
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
'''
|
||||
Unit tests for `tractor.trionics.supervise_run_process` (in
|
||||
`tractor.trionics._subproc`) and its per-line std-stream relay.
|
||||
|
||||
Hermetic `trio`-only coverage (no actor-runtime needed):
|
||||
|
||||
- per-line stdout relay -> `log.io`
|
||||
- parent controlling-tty isolation (child fd1 is a pipe, fd0
|
||||
`/dev/null` — never the parent `/dev/pts/*`)
|
||||
- mandatory concurrent pipe-drain (no deadlock on >64KiB
|
||||
no-newline output)
|
||||
- live stderr relay + `CalledProcessError` rebuild (rc!=0 note)
|
||||
- legacy capture-stderr CPE note path
|
||||
|
||||
'''
|
||||
from functools import partial
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from tractor.trionics import (
|
||||
_subproc,
|
||||
collapse_eg,
|
||||
supervise_run_process,
|
||||
)
|
||||
|
||||
|
||||
def _capture_relay(monkeypatch, level: str = 'io') -> list[str]:
|
||||
'''
|
||||
Redirect `_subproc.log.<level>` (the relay's emit method —
|
||||
`io` by default, see `supervise_run_process(relay_level=...)`)
|
||||
into a list so tests can assert on the relayed lines.
|
||||
|
||||
'''
|
||||
records: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
_subproc.log,
|
||||
level,
|
||||
lambda msg, *a, **k: records.append(msg),
|
||||
)
|
||||
return records
|
||||
|
||||
|
||||
def test_stdout_relayed_per_line(monkeypatch):
|
||||
records = _capture_relay(monkeypatch)
|
||||
|
||||
cmd = [
|
||||
'sh', '-c',
|
||||
'for i in 1 2 3; do echo line=$i; done',
|
||||
]
|
||||
|
||||
async def main():
|
||||
async with trio.open_nursery() as tn:
|
||||
await tn.start(
|
||||
partial(
|
||||
supervise_run_process,
|
||||
cmd,
|
||||
label='t-out',
|
||||
relay_stdout=True,
|
||||
)
|
||||
)
|
||||
|
||||
trio.run(main)
|
||||
|
||||
out_lines = [r for r in records if '[t-out:out]' in r]
|
||||
assert any('line=1' in r for r in out_lines)
|
||||
assert any('line=2' in r for r in out_lines)
|
||||
assert any('line=3' in r for r in out_lines)
|
||||
|
||||
|
||||
def test_parent_tty_isolated(monkeypatch):
|
||||
records = _capture_relay(monkeypatch)
|
||||
|
||||
cmd = [
|
||||
'sh', '-c',
|
||||
'readlink /proc/self/fd/0; readlink /proc/self/fd/1',
|
||||
]
|
||||
|
||||
async def main():
|
||||
async with trio.open_nursery() as tn:
|
||||
await tn.start(
|
||||
partial(
|
||||
supervise_run_process,
|
||||
cmd,
|
||||
label='t-tty',
|
||||
relay_stdout=True,
|
||||
)
|
||||
)
|
||||
|
||||
trio.run(main)
|
||||
|
||||
relayed = '\n'.join(records)
|
||||
# fd1 (stdout) must be OUR pipe, never a controlling tty.
|
||||
assert 'pipe:' in relayed
|
||||
assert '/dev/pts/' not in relayed
|
||||
# fd0 (stdin) is pinned to DEVNULL.
|
||||
assert '/dev/null' in relayed
|
||||
|
||||
|
||||
def test_no_deadlock_on_big_unnewlined_output(monkeypatch):
|
||||
'''
|
||||
>64KiB of output with NO newline: only completes because the
|
||||
relay reader concurrently drains the pipe (else the child
|
||||
blocks on `write()` when the OS pipe buffer fills).
|
||||
|
||||
'''
|
||||
records = _capture_relay(monkeypatch)
|
||||
|
||||
cmd = [
|
||||
'sh', '-c',
|
||||
'head -c 200000 /dev/zero | tr "\\0" x',
|
||||
]
|
||||
|
||||
async def main():
|
||||
# generous vs the ~ms real runtime, but bounded so a
|
||||
# genuine pipe-fill deadlock fails fast.
|
||||
with trio.fail_after(2):
|
||||
async with trio.open_nursery() as tn:
|
||||
await tn.start(
|
||||
partial(
|
||||
supervise_run_process,
|
||||
cmd,
|
||||
label='t-big',
|
||||
relay_stdout=True,
|
||||
)
|
||||
)
|
||||
|
||||
trio.run(main)
|
||||
|
||||
big = ''.join(
|
||||
r.split('] ', 1)[-1]
|
||||
for r in records
|
||||
if '[t-big:out]' in r
|
||||
)
|
||||
assert len(big) == 200_000
|
||||
|
||||
|
||||
def test_stderr_relay_and_cpe_rebuild(monkeypatch):
|
||||
'''
|
||||
`relay_stderr=True` PIPEs stderr ourselves (mutually
|
||||
exclusive with trio's `capture_stderr`), so on rc!=0 the
|
||||
wrapper rebuilds a `CalledProcessError` from the live
|
||||
accumulator and `.add_note()`s its `.stderr` — AND the
|
||||
stderr is relayed per-line live.
|
||||
|
||||
'''
|
||||
records = _capture_relay(monkeypatch)
|
||||
|
||||
cmd = [
|
||||
'sh', '-c',
|
||||
'echo boom 1>&2; exit 3',
|
||||
]
|
||||
|
||||
async def main():
|
||||
# `collapse_eg()` unwraps the parent-nursery's single-exc
|
||||
# eg so the bare CPE bubbles straight out (mirrors real
|
||||
# caller usage).
|
||||
async with (
|
||||
collapse_eg(),
|
||||
trio.open_nursery() as tn,
|
||||
):
|
||||
await tn.start(
|
||||
partial(
|
||||
supervise_run_process,
|
||||
cmd,
|
||||
label='t-err',
|
||||
relay_stderr=True,
|
||||
check=True,
|
||||
)
|
||||
)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as ei:
|
||||
trio.run(main)
|
||||
|
||||
cpe = ei.value
|
||||
assert cpe.returncode == 3
|
||||
# rebuilt `.stderr` (trio did NOT capture since we PIPE'd it).
|
||||
assert b'boom' in (cpe.stderr or b'')
|
||||
# note attached for legible teardown reporting.
|
||||
assert any(
|
||||
'boom' in n
|
||||
for n in getattr(cpe, '__notes__', [])
|
||||
)
|
||||
# AND it was relayed live per-line.
|
||||
assert any(
|
||||
'[t-err:err]' in r and 'boom' in r
|
||||
for r in records
|
||||
)
|
||||
|
||||
|
||||
def test_nonrelay_cpe_note(monkeypatch):
|
||||
'''
|
||||
No live relay: stderr is silently drained + captured (NOT
|
||||
emitted), and on rc!=0 the wrapper rebuilds the
|
||||
`CalledProcessError` from that accumulator with a `.stderr`
|
||||
note — same deterministic post-drain path as the relay case.
|
||||
|
||||
'''
|
||||
cmd = [
|
||||
'sh', '-c',
|
||||
'echo nope 1>&2; exit 7',
|
||||
]
|
||||
|
||||
async def main():
|
||||
async with (
|
||||
collapse_eg(),
|
||||
trio.open_nursery() as tn,
|
||||
):
|
||||
await tn.start(
|
||||
partial(
|
||||
supervise_run_process,
|
||||
cmd,
|
||||
label='t-legacy',
|
||||
check=True,
|
||||
# relay_* default False -> silent
|
||||
# drain+capture for the CPE note.
|
||||
)
|
||||
)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as ei:
|
||||
trio.run(main)
|
||||
|
||||
cpe = ei.value
|
||||
assert cpe.returncode == 7
|
||||
assert b'nope' in (cpe.stderr or b'')
|
||||
assert any(
|
||||
'nope' in n
|
||||
for n in getattr(cpe, '__notes__', [])
|
||||
)
|
||||
|
|
@ -15,16 +15,23 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
This is the "bootloader" for actors started using the native trio backend.
|
||||
The "bootloader" for sub-actors spawned via the native `trio`
|
||||
backend (the default `python -m tractor._child` CLI entry) and
|
||||
the in-process `subint` backend (`tractor.spawn._subint`).
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
|
||||
from ast import literal_eval
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .runtime._runtime import Actor
|
||||
from .spawn._entry import _trio_main
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .discovery._addr import UnwrappedAddress
|
||||
from .spawn._spawn import SpawnMethodKey
|
||||
|
||||
|
||||
def parse_uid(arg):
|
||||
name, uuid = literal_eval(arg) # ensure 2 elements
|
||||
|
|
@ -39,6 +46,73 @@ def parse_ipaddr(arg):
|
|||
return arg
|
||||
|
||||
|
||||
def _actor_child_main(
|
||||
uid: tuple[str, str],
|
||||
loglevel: str | None,
|
||||
parent_addr: UnwrappedAddress | None,
|
||||
infect_asyncio: bool,
|
||||
spawn_method: SpawnMethodKey = 'trio',
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
Construct the child `Actor` and dispatch to `_trio_main()`.
|
||||
|
||||
Shared entry shape used by both the `python -m tractor._child`
|
||||
CLI (trio/mp subproc backends) and the `subint` backend, which
|
||||
invokes this from inside a fresh `concurrent.interpreters`
|
||||
sub-interpreter via `Interpreter.call()`.
|
||||
|
||||
'''
|
||||
# Apply defensive monkey-patches for upstream `trio`
|
||||
# bugs we've encountered while running tractor — see
|
||||
# `tractor.trionics.patches` for the catalog +
|
||||
# per-patch upstream-fix tracking. Must run BEFORE
|
||||
# any trio runtime init.
|
||||
from .trionics.patches import apply_all
|
||||
apply_all()
|
||||
|
||||
subactor = Actor(
|
||||
name=uid[0],
|
||||
uuid=uid[1],
|
||||
loglevel=loglevel,
|
||||
spawn_method=spawn_method,
|
||||
)
|
||||
|
||||
# XXX, set a stable OS-level proc-title BEFORE entering
|
||||
# the trio runtime so `ps`/`top`/`acli.pytree` and
|
||||
# orphan-reapers can identify this actor for its full
|
||||
# lifetime — e.g.
|
||||
# `tractor[doggy@1027301b]`
|
||||
# vs. the default uninformative
|
||||
# `python -m tractor._child --uid (...)`
|
||||
#
|
||||
# `setproctitle` mutates `argv[0]` (visible in
|
||||
# `/proc/<pid>/cmdline`) AND the kernel `comm`
|
||||
# (visible in `/proc/<pid>/comm`, kernel-truncated to
|
||||
# ~15 bytes, but preserved through zombie state). Both
|
||||
# surfaces are enough for `_testing._reap` /
|
||||
# `acli.reap` orphan- and zombie-detection to identify
|
||||
# tractor sub-actors via intrinsic signals — no cwd,
|
||||
# venv path, or env-var coincidence-of-implementation
|
||||
# matching needed.
|
||||
#
|
||||
# NB: an earlier draft also wrote `TRACTOR_AID` to
|
||||
# `os.environ` here for `pgrep --env`-style discovery,
|
||||
# but Linux snapshots `/proc/<pid>/environ` at exec/fork
|
||||
# time, so post-fork runtime mutations don't propagate
|
||||
# to the kernel-visible env. The proc-title path
|
||||
# provides equivalent ergonomics
|
||||
# (`pgrep -f 'tractor\['`) without that gotcha.
|
||||
from .devx._proctitle import set_actor_proctitle
|
||||
set_actor_proctitle(subactor)
|
||||
|
||||
_trio_main(
|
||||
subactor,
|
||||
parent_addr=parent_addr,
|
||||
infect_asyncio=infect_asyncio,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
__tracebackhide__: bool = True
|
||||
|
||||
|
|
@ -49,15 +123,10 @@ if __name__ == "__main__":
|
|||
parser.add_argument("--asyncio", action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
subactor = Actor(
|
||||
name=args.uid[0],
|
||||
uuid=args.uid[1],
|
||||
_actor_child_main(
|
||||
uid=args.uid,
|
||||
loglevel=args.loglevel,
|
||||
spawn_method="trio"
|
||||
)
|
||||
|
||||
_trio_main(
|
||||
subactor,
|
||||
parent_addr=args.parent_addr,
|
||||
infect_asyncio=args.asyncio,
|
||||
spawn_method='trio',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,28 @@ class ActorFailure(RuntimeFailure):
|
|||
'''
|
||||
|
||||
|
||||
class ActorTooSlowError(RuntimeFailure):
|
||||
'''
|
||||
A peer-`Actor` failed to ack an actor-runtime cancel-cascade
|
||||
request (e.g. `Portal.cancel_actor()` -> `Actor.cancel()`)
|
||||
within the bounded wait window.
|
||||
|
||||
Distinct exc-type (NOT a `trio.TooSlowError` subclass) so that
|
||||
`except trio.TooSlowError:` blocks elsewhere in the test-suite
|
||||
or `tractor` internals do NOT silently mask actor-cancel
|
||||
timeouts — these MUST propagate so a supervisor can escalate
|
||||
to `proc.terminate()` (hard-kill) per SC-discipline:
|
||||
|
||||
graceful cancel-req -> bounded wait -> hard-kill
|
||||
|
||||
Reason: see #subint_forkserver duplicate-name hang
|
||||
diagnosis where `Portal.cancel_actor()` silently swallowed
|
||||
the timeout and the supervisor never escalated, leaving
|
||||
a same-named sibling subactor parked forever.
|
||||
|
||||
'''
|
||||
|
||||
|
||||
class InternalError(RuntimeError):
|
||||
'''
|
||||
Entirely unexpected internal machinery error indicating
|
||||
|
|
|
|||
158
tractor/_root.py
158
tractor/_root.py
|
|
@ -69,6 +69,20 @@ from ._exceptions import (
|
|||
logger = log.get_logger('tractor')
|
||||
|
||||
|
||||
# Spawn backends under which `debug_mode=True` is supported.
|
||||
# Requirement: the spawned subactor's root runtime must be
|
||||
# trio-native so `tractor.devx.debug._tty_lock` works. Matches
|
||||
# both the enable-site in `open_root_actor` and the cleanup-
|
||||
# site reset of `_runtime_vars['_debug_mode']` — keep them in
|
||||
# lockstep when adding backends.
|
||||
_DEBUG_COMPATIBLE_BACKENDS: tuple[str, ...] = (
|
||||
'trio',
|
||||
# forkserver children run `_trio_main` in their own OS
|
||||
# process — same child-side runtime shape as `trio_proc`.
|
||||
'main_thread_forkserver',
|
||||
)
|
||||
|
||||
|
||||
# TODO: stick this in a `@acm` defined in `devx.debug`?
|
||||
# -[ ] also maybe consider making this a `wrapt`-deco to
|
||||
# save an indent level?
|
||||
|
|
@ -141,7 +155,6 @@ async def maybe_block_bp(
|
|||
os.environ.pop('PYTHONBREAKPOINT', None)
|
||||
|
||||
|
||||
|
||||
@acm
|
||||
async def open_root_actor(
|
||||
*,
|
||||
|
|
@ -172,6 +185,7 @@ async def open_root_actor(
|
|||
# enables the multi-process debugger support
|
||||
debug_mode: bool = False,
|
||||
maybe_enable_greenback: bool = False, # `.pause_from_sync()/breakpoint()` support
|
||||
|
||||
# ^XXX NOTE^ the perf implications of use,
|
||||
# https://greenback.readthedocs.io/en/latest/principle.html#performance
|
||||
enable_stack_on_sig: bool = False,
|
||||
|
|
@ -227,6 +241,7 @@ async def open_root_actor(
|
|||
f'_registry_addrs: {registry_addrs!r}\n'
|
||||
)
|
||||
|
||||
# debug.mk_pdb().set_trace()
|
||||
async with maybe_block_bp(
|
||||
debug_mode=debug_mode,
|
||||
maybe_enable_greenback=maybe_enable_greenback,
|
||||
|
|
@ -270,6 +285,82 @@ async def open_root_actor(
|
|||
)
|
||||
enable_modules.extend(rpc_module_paths)
|
||||
|
||||
# `TRACTOR_LOGLEVEL` env-var wins over any caller-passed
|
||||
# `loglevel` so devs/test-runs can crank (or silence)
|
||||
# console verbosity without touching application code.
|
||||
env_ll_report: str = ''
|
||||
if env_ll := os.environ.get('TRACTOR_LOGLEVEL'):
|
||||
# capture the caller-passed value BEFORE the env-var
|
||||
# clobbers it, else the override-notice below is dead
|
||||
# code (the `!=` compare is always `False`).
|
||||
caller_ll: str|None = loglevel
|
||||
loglevel = env_ll
|
||||
env_ll_report: str = (
|
||||
f'Detected env-var setting,\n'
|
||||
f'TRACTOR_LOGLEVEL={env_ll!r}\n'
|
||||
f'\n'
|
||||
f'Setting console loglevel per,\n'
|
||||
f'loglevel={loglevel!r}\n'
|
||||
)
|
||||
if (
|
||||
caller_ll
|
||||
and
|
||||
caller_ll.upper() != env_ll.upper()
|
||||
):
|
||||
env_ll_report += (
|
||||
f'\n'
|
||||
f'NOTE env-var OVERRIDES caller-passed,\n'
|
||||
f'loglevel={caller_ll!r}\n'
|
||||
)
|
||||
|
||||
loglevel: str = (
|
||||
loglevel
|
||||
or
|
||||
log._default_loglevel
|
||||
)
|
||||
loglevel: str = loglevel.upper()
|
||||
|
||||
assert loglevel
|
||||
_log = log.get_console_log(
|
||||
level=loglevel,
|
||||
name='tractor',
|
||||
logger=logger,
|
||||
)
|
||||
assert _log
|
||||
if env_ll_report:
|
||||
_log.info(env_ll_report)
|
||||
|
||||
# `TRACTOR_SPAWN_METHOD` env-var wins over any caller-passed
|
||||
# `start_method` so devs/test-runs can swap the actor spawn
|
||||
# backend without touching application code (e.g. driving
|
||||
# the `examples/debugging/<script>.py` suite under each
|
||||
# backend from `tests/devx/conftest.py::spawn`).
|
||||
if env_sm := os.environ.get('TRACTOR_SPAWN_METHOD'):
|
||||
# capture the caller-passed value BEFORE the env-var
|
||||
# clobbers it (else the override-notice is dead code).
|
||||
caller_sm: str|None = start_method
|
||||
start_method: str = env_sm
|
||||
env_sm_report: str = (
|
||||
f'Detected env-var setting,\n'
|
||||
f'TRACTOR_SPAWN_METHOD={env_sm!r}\n'
|
||||
f'\n'
|
||||
f'Setting spawn backend as,\n'
|
||||
f'start_method={env_sm!r}\n'
|
||||
)
|
||||
if (
|
||||
caller_sm
|
||||
and
|
||||
caller_sm != env_sm
|
||||
):
|
||||
_log.warning(
|
||||
env_sm_report
|
||||
+
|
||||
f'NOTE env-var OVERRIDES caller-passed,\n'
|
||||
f'`start_method={caller_sm!r}`\n'
|
||||
)
|
||||
else:
|
||||
_log.info(env_sm_report)
|
||||
|
||||
if start_method is not None:
|
||||
_spawn.try_set_start_method(start_method)
|
||||
|
||||
|
|
@ -286,17 +377,44 @@ async def open_root_actor(
|
|||
wrap_address(uw_addr)
|
||||
for uw_addr in uw_reg_addrs
|
||||
]
|
||||
loglevel: str = (
|
||||
loglevel
|
||||
or
|
||||
log._default_loglevel
|
||||
)
|
||||
loglevel: str = loglevel.upper()
|
||||
|
||||
# fail-fast on `enable_transports` / `registry_addrs` proto
|
||||
# mismatch — historically this caused a silent indefinite
|
||||
# hang during the registrar handshake (registry was reachable
|
||||
# only via a transport not in `enable_transports`, so the
|
||||
# actor could never connect to register/discover). See
|
||||
# `tests/ipc/test_multi_tpt.py::test_root_passes_tpt_to_sub`
|
||||
# for the foot-gun case + its layer-1 skip-guard.
|
||||
bad_addrs: list[tuple[str, Address]] = [
|
||||
(addr.proto_key, addr)
|
||||
for addr in registry_addrs
|
||||
if addr.proto_key not in enable_transports
|
||||
]
|
||||
if bad_addrs:
|
||||
mismatch_lines: str = '\n'.join(
|
||||
f' - proto_key={pk!r} addr={a!r}'
|
||||
for pk, a in bad_addrs
|
||||
)
|
||||
raise ValueError(
|
||||
f'`registry_addrs` contains addr(s) whose proto is '
|
||||
f'not in `enable_transports`!\n'
|
||||
f'enable_transports: {enable_transports!r}\n'
|
||||
f'mismatched_addrs:\n'
|
||||
f'{mismatch_lines}\n'
|
||||
f'\n'
|
||||
f'Either add the missing proto to '
|
||||
f'`enable_transports`, or remove the addr from '
|
||||
f'`registry_addrs`.'
|
||||
)
|
||||
|
||||
# Debug-mode is currently only supported for backends whose
|
||||
# subactor root runtime is trio-native (so `tractor.devx.
|
||||
# debug._tty_lock` works). See `_DEBUG_COMPATIBLE_BACKENDS`
|
||||
# module-const for the list.
|
||||
if (
|
||||
debug_mode
|
||||
and
|
||||
_spawn._spawn_method == 'trio'
|
||||
_spawn._spawn_method in _DEBUG_COMPATIBLE_BACKENDS
|
||||
):
|
||||
_state._runtime_vars['_debug_mode'] = True
|
||||
|
||||
|
|
@ -318,22 +436,18 @@ async def open_root_actor(
|
|||
|
||||
elif debug_mode:
|
||||
raise RuntimeError(
|
||||
"Debug mode is only supported for the `trio` backend!"
|
||||
f'Debug mode currently supported only for '
|
||||
f'{_DEBUG_COMPATIBLE_BACKENDS!r} spawn backends, not '
|
||||
f'{_spawn._spawn_method!r}.'
|
||||
)
|
||||
|
||||
assert loglevel
|
||||
_log = log.get_console_log(
|
||||
level=loglevel,
|
||||
name='tractor',
|
||||
)
|
||||
assert _log
|
||||
|
||||
# TODO: factor this into `.devx._stackscope`!!
|
||||
if (
|
||||
debug_mode
|
||||
and
|
||||
enable_stack_on_sig
|
||||
):
|
||||
#
|
||||
# NOTE, intentionally NOT gated on `debug_mode` so SIGUSR1
|
||||
# task-tree dumps work in plain (non-pdb) runs too — esp.
|
||||
# in infected-`asyncio` root processes where the default
|
||||
# SIGUSR1 action would otherwise terminate the proc.
|
||||
if enable_stack_on_sig:
|
||||
from .devx._stackscope import enable_stack_on_sig
|
||||
enable_stack_on_sig()
|
||||
|
||||
|
|
@ -619,7 +733,7 @@ async def open_root_actor(
|
|||
if (
|
||||
debug_mode
|
||||
and
|
||||
_spawn._spawn_method == 'trio'
|
||||
_spawn._spawn_method in _DEBUG_COMPATIBLE_BACKENDS
|
||||
):
|
||||
_state._runtime_vars['_debug_mode'] = False
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -22,6 +22,7 @@ Might be eventually useful to expose as a util set from
|
|||
our `tractor.discovery` subsys?
|
||||
|
||||
'''
|
||||
import os
|
||||
import random
|
||||
from typing import (
|
||||
Type,
|
||||
|
|
@ -31,17 +32,28 @@ from tractor.discovery import _addr
|
|||
|
||||
def get_rando_addr(
|
||||
tpt_proto: str,
|
||||
*,
|
||||
|
||||
# choose random port at import time
|
||||
_rando_port: str = random.randint(1000, 9999)
|
||||
|
||||
) -> tuple[str, str|int]:
|
||||
'''
|
||||
Used to globally override the runtime to the
|
||||
per-test-session-dynamic addr so that all tests never conflict
|
||||
with any other actor tree using the default.
|
||||
|
||||
Cross-process isolation: TCP-port picks salt
|
||||
`random.randint()` with `os.getpid()` so two parallel
|
||||
pytest sessions (e.g. one running `--tpt-proto=tcp` and
|
||||
another `--tpt-proto=uds` concurrently) almost-never
|
||||
collide on the same port. Without the salt, the prior
|
||||
impl's import-time `random.randint(1000, 9999)` default
|
||||
arg was effectively a process-singleton with a 1/9000
|
||||
chance of cross-run collision per pair — and when it
|
||||
happened EVERY `reg_addr`-using test in BOTH runs would
|
||||
fight over the bind, cascading into a chain of
|
||||
"Address already in use" failures.
|
||||
|
||||
For UDS this concern doesn't apply: `UDSAddress.get_random()`
|
||||
already builds socket paths from `os.getpid()` so each
|
||||
pytest process gets its own socket-path namespace.
|
||||
|
||||
'''
|
||||
addr_type: Type[_addr.Addres] = _addr._address_types[tpt_proto]
|
||||
def_reg_addr: tuple[str, int] = _addr._default_lo_addrs[tpt_proto]
|
||||
|
|
@ -51,9 +63,21 @@ def get_rando_addr(
|
|||
testrun_reg_addr: tuple[str, int|str]
|
||||
match tpt_proto:
|
||||
case 'tcp':
|
||||
# Per-call randomness mixed with `os.getpid()` —
|
||||
# see the docstring above for the cross-process
|
||||
# isolation rationale. The mix means:
|
||||
# - within one pytest session, two calls return
|
||||
# distinct ports (good for tests that need a
|
||||
# second-different-reg-addr in one fn body, e.g.
|
||||
# `test_tpt_bind_addrs::bind-subset-reg`),
|
||||
# - across parallel pytest sessions, the pid bias
|
||||
# makes coincident port choices unlikely.
|
||||
port: int = 1000 + (
|
||||
random.randint(0, 8999) + os.getpid()
|
||||
) % 9000
|
||||
testrun_reg_addr = (
|
||||
addr_type.def_bindspace,
|
||||
_rando_port,
|
||||
port,
|
||||
)
|
||||
|
||||
# NOTE, file-name uniqueness (no-collisions) will be based on
|
||||
|
|
|
|||
|
|
@ -24,16 +24,192 @@ from functools import (
|
|||
wraps,
|
||||
)
|
||||
import inspect
|
||||
import os
|
||||
import platform
|
||||
from typing import (
|
||||
Callable,
|
||||
get_args,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
import tractor
|
||||
from tractor.spawn._spawn import SpawnMethodKey
|
||||
import trio
|
||||
|
||||
# Re-export `_testing.trace`'s pytest fixtures so they're
|
||||
# picked up by pytest's plugin-discovery (this module is
|
||||
# loaded via `pytest_plugins` from `pyproject.toml`). The
|
||||
# `noqa: F401` annotations make linters tolerate the
|
||||
# unused-looking imports — they're load-bearing for pytest
|
||||
# discovery. The fixtures share their `name=` kw with the
|
||||
# underlying CM functions; the python-level identifiers
|
||||
# below carry the `_fixture` suffix to avoid module-scope
|
||||
# collision (see `_testing/trace.py` for details).
|
||||
from .trace import ( # noqa: F401
|
||||
afk_alarm_w_trace_fixture,
|
||||
fail_after_w_trace_fixture,
|
||||
)
|
||||
|
||||
# Spawn-backend keys which may appear in `skipon_spawn_backend`
|
||||
# marks ahead of the named backend actually being registered in
|
||||
# `tractor.spawn._spawn.SpawnMethodKey`; such marks are inert
|
||||
# (they can never match an active backend) but must not break
|
||||
# collection.
|
||||
_IN_DEV_SPAWN_BACKENDS: tuple[str, ...] = (
|
||||
'subint',
|
||||
'subint_forkserver',
|
||||
'main_thread_forkserver',
|
||||
)
|
||||
|
||||
# Sub-plugin: zombie-subactor + UDS sock-file + shm
|
||||
# reaping fixtures live in `tractor._testing._reap`
|
||||
# alongside the underlying detection/cleanup helpers.
|
||||
# Loading `_reap` as a sub-plugin here keeps reaping
|
||||
# concerns co-located + this module focused on tractor-
|
||||
# tooling-specific hooks (option/marker/parametrize,
|
||||
# `tractor_test` deco, transport / spawn-method
|
||||
# fixtures).
|
||||
pytest_plugins: tuple[str, ...] = (
|
||||
'tractor._testing._reap',
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import Namespace
|
||||
|
||||
|
||||
_cap_sys_passed_as_flag: bool = False
|
||||
|
||||
# Spawn backends that need `--capture=sys` to avoid the
|
||||
# fork-child×pytest-capture-fd deadlock. See the long
|
||||
# NOTE in `pytest_load_initial_conftests` below for the
|
||||
# full mechanism + tradeoff write-up.
|
||||
_CAPSYS_REQUIRED_SPAWNERS: frozenset[str] = frozenset({
|
||||
'main_thread_forkserver',
|
||||
# TODO future variant-2 'subint_forkserver' lands
|
||||
# here too once the impl is unblocked.
|
||||
})
|
||||
|
||||
|
||||
# XXX REQUIRED in order to enforce `--capture=` flag
|
||||
# pre test session.
|
||||
# https://docs.pytest.org/en/stable/reference/reference.html#bootstrapping-hooks
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
def pytest_load_initial_conftests(
|
||||
early_config: pytest.Config,
|
||||
parser: pytest.Parser,
|
||||
args: list[str],
|
||||
):
|
||||
'''
|
||||
Validate the `--capture=` × `--spawn-backend=`
|
||||
combination at session-startup.
|
||||
|
||||
Background
|
||||
----------
|
||||
`--capture=sys` is REQUIRED for fork-based spawn backends (e.g.
|
||||
`main_thread_forkserver`): default `--capture=fd` redirects fd
|
||||
1,2 to temp files, and fork children inherit those fds — opaque
|
||||
deadlocks happen in the pytest-capture-machinery ↔ fork-child
|
||||
stdio interaction. `--capture=sys` only redirects Python- level
|
||||
`sys.stdout`/`sys.stderr`, leaving fd 1,2 alone.
|
||||
|
||||
Trade-off (vs. `--capture=fd`):
|
||||
|
||||
- LOST: per-test attribution of subactor *raw-fd* output (C-ext
|
||||
writes, `os.write(2, ...)`, subproc stdout). Not zero — those
|
||||
go to the terminal, captured by CI's terminal-level capture,
|
||||
just not per-test-scoped in the pytest failure report.
|
||||
|
||||
- KEPT: Python-level `print()` + `logging` capture per-test
|
||||
(tractor's logger uses `sys.stderr`, so tractor log output IS
|
||||
still attributed per-test).
|
||||
|
||||
- KEPT: user `pytest -s` for debugging (unaffected).
|
||||
|
||||
Full post-mortem in
|
||||
`ai/conc-anal/subint_forkserver_test_cancellation_leak_issue.md`.
|
||||
|
||||
Validation policy:
|
||||
- **CI mode** (`CI` env-var set): fail-fast at
|
||||
session start if a fork-spawn backend is requested
|
||||
WITHOUT `--capture=sys`. CI must be explicit; no
|
||||
auto-fallbacks. Forces every CI matrix-row's run
|
||||
line to declare its capture mode plainly.
|
||||
- **Local mode** (no `CI` env-var): emit a loud
|
||||
warning + suggest `--capture=sys`, but allow the
|
||||
run to proceed. Lets devs experiment with the bad
|
||||
combo (e.g. to validate whether recent
|
||||
fork-survival fixes have made `--capture=fd` work
|
||||
after all).
|
||||
|
||||
'''
|
||||
global _cap_sys_passed_as_flag
|
||||
opts_w_args: Namespace = parser.parse_known_args(args)
|
||||
spawner: str|None = getattr(
|
||||
opts_w_args,
|
||||
'spawn_backend',
|
||||
None,
|
||||
)
|
||||
capture: str|None = getattr(
|
||||
opts_w_args,
|
||||
'capture',
|
||||
None,
|
||||
)
|
||||
if '--capture=sys' in args:
|
||||
_cap_sys_passed_as_flag = True
|
||||
assert capture == 'sys'
|
||||
|
||||
in_ci: bool = bool(os.environ.get('CI'))
|
||||
|
||||
if (
|
||||
spawner in _CAPSYS_REQUIRED_SPAWNERS
|
||||
and
|
||||
capture == 'fd'
|
||||
):
|
||||
msg: str = (
|
||||
f'\n'
|
||||
f'XXX `--spawn-backend={spawner}` REQUIRES '
|
||||
f'`--capture=sys` XXX\n'
|
||||
f'fork-child × `--capture=fd` is a known '
|
||||
f'deadlock pattern.\n'
|
||||
f'See `tractor._testing.pytest`\'s '
|
||||
f'`pytest_load_initial_conftests` docstring '
|
||||
f'for the full mechanism.\n'
|
||||
f'\n'
|
||||
f'Re-invoke with `--capture=sys` (or run '
|
||||
f'with `pytest -s` for no capture).\n'
|
||||
)
|
||||
# fail-fast: CI must declare capture explicitly for
|
||||
# fork-spawn backends.
|
||||
if in_ci:
|
||||
pytest.exit(
|
||||
f'{msg}\n'
|
||||
f'FAIL-FAST: CI=1 detected; aborting session.\n',
|
||||
returncode=2,
|
||||
)
|
||||
|
||||
# local: loud warn but let the run proceed so devs can
|
||||
# experiment.
|
||||
else:
|
||||
warnings.warn(
|
||||
f'{msg}\n'
|
||||
f'Local mode (no `CI` env var) — '
|
||||
f'continuing. Expect potential hangs.\n',
|
||||
category=UserWarning,
|
||||
stacklevel=1,
|
||||
)
|
||||
# ??TODO?? is there a way to force the `--capture=sys` sin CLI ??
|
||||
# - [x] ask pytest peeps in chat!
|
||||
# - [x] pytest` issue,
|
||||
# https://github.com/pytest-dev/pytest/issues/14444
|
||||
|
||||
# TODO, set various `$TRACTOR_X*` osenv vars here!
|
||||
print(
|
||||
f'Applying `tractor`-specific `pytest` config,\n'
|
||||
f'{opts_w_args!r}\n'
|
||||
)
|
||||
|
||||
|
||||
def tractor_test(
|
||||
wrapped: Callable|None = None,
|
||||
|
|
@ -112,11 +288,17 @@ def tractor_test(
|
|||
# injection (via `__wrapped__`) without leaking the async
|
||||
# nature.
|
||||
@wraps(wrapped)
|
||||
def wrapper(**kwargs):
|
||||
def wrapper(
|
||||
set_fork_aware_capture: pytest.CaptureFixture|None = None,
|
||||
# ^NOTE when set, the decorated fn declared as fixture-param.
|
||||
|
||||
**kwargs,
|
||||
):
|
||||
__tracebackhide__: bool = hide_tb
|
||||
|
||||
# NOTE, ensure we inject any test-fn declared fixture
|
||||
# names.
|
||||
sig = inspect.signature(wrapped)
|
||||
for kw in [
|
||||
'reg_addr',
|
||||
'loglevel',
|
||||
|
|
@ -125,9 +307,13 @@ def tractor_test(
|
|||
'tpt_proto',
|
||||
'timeout',
|
||||
]:
|
||||
if kw in inspect.signature(wrapped).parameters:
|
||||
if kw in sig.parameters:
|
||||
assert kw in kwargs
|
||||
|
||||
if 'set_fork_aware_capture' in sig.parameters:
|
||||
assert set_fork_aware_capture
|
||||
kwargs['set_fork_aware_capture'] = set_fork_aware_capture
|
||||
|
||||
# Extract runtime settings as locals for
|
||||
# `open_root_actor()`; these must NOT leak into
|
||||
# `kwargs` when the test fn doesn't declare them
|
||||
|
|
@ -170,7 +356,6 @@ def tractor_test(
|
|||
# invoke test-fn body IN THIS task
|
||||
await wrapped(**kwargs)
|
||||
|
||||
# invoke runtime via a root task.
|
||||
return trio.run(
|
||||
partial(
|
||||
_main,
|
||||
|
|
@ -184,13 +369,6 @@ def tractor_test(
|
|||
def pytest_addoption(
|
||||
parser: pytest.Parser,
|
||||
):
|
||||
# parser.addoption(
|
||||
# "--ll",
|
||||
# action="store",
|
||||
# dest='loglevel',
|
||||
# default='ERROR', help="logging level to set when testing"
|
||||
# )
|
||||
|
||||
parser.addoption(
|
||||
"--spawn-backend",
|
||||
action="store",
|
||||
|
|
@ -212,6 +390,21 @@ def pytest_addoption(
|
|||
),
|
||||
)
|
||||
|
||||
parser.addoption(
|
||||
"--enable-stackscope",
|
||||
action="store_true",
|
||||
dest='enable_stackscope',
|
||||
default=False,
|
||||
help=(
|
||||
'Install `stackscope` SIGUSR1 handler in pytest + '
|
||||
'every spawned subactor for live trio task-tree '
|
||||
'dumps during hang investigations. Lighter than '
|
||||
'`--tpdb` (no pdb machinery / tty-lock contention) '
|
||||
'— use when you only need stack visibility. To '
|
||||
'capture: `kill -USR1 <pytest-or-subactor-pid>`.'
|
||||
),
|
||||
)
|
||||
|
||||
# provide which IPC transport protocols opting-in test suites
|
||||
# should accumulatively run against.
|
||||
parser.addoption(
|
||||
|
|
@ -223,11 +416,66 @@ def pytest_addoption(
|
|||
help="Transport protocol to use under the `tractor.ipc.Channel`",
|
||||
)
|
||||
|
||||
# console loglevel for the test-session, scoped to the
|
||||
# consuming-project's OWN pkg-hierarchy (see the
|
||||
# `testing_pkg_name` fixture). For `tractor` itself this IS the
|
||||
# runtime loglevel; downstream projects use `--ll` for their own
|
||||
# ("internal") app-logging and `--tl` for tractor-as-runtime.
|
||||
parser.addoption(
|
||||
"--ll",
|
||||
"--loglevel",
|
||||
action="store",
|
||||
dest='loglevel',
|
||||
default=None,
|
||||
help=(
|
||||
"console loglevel to set for the test session, scoped to "
|
||||
"the consuming-project pkg (see `testing_pkg_name`). "
|
||||
"Falls through as the `--tl` default."
|
||||
),
|
||||
)
|
||||
|
||||
def pytest_configure(config):
|
||||
backend = config.option.spawn_backend
|
||||
# tractor-as-runtime loglevel, DISTINCT from `--ll` so downstream
|
||||
# projects can split their app-logs from the `tractor.*` runtime
|
||||
# hierarchy. Accepts a `tractor.log` "logging-spec" (see
|
||||
# `tractor.log.apply_logspec()`).
|
||||
parser.addoption(
|
||||
"--tl",
|
||||
"--tractor-loglevel",
|
||||
action="store",
|
||||
dest='tractor_loglevel',
|
||||
default=None,
|
||||
help=(
|
||||
"loglevel (or logging-spec) for `tractor`-as-runtime, "
|
||||
"distinct from `--ll`. Accepts a bare level (eg. "
|
||||
"'info', 'cancel') or a sub-logger filter-spec, "
|
||||
"'<sublog>:<level>,...' (eg. "
|
||||
"'devx:runtime,trionics:cancel'). Falls back to `--ll` "
|
||||
"when unset. Mirrors the logging-spec grammar consumed "
|
||||
"by `tractor.log.apply_logspec()` (see its sub-pkg "
|
||||
"granularity caveat)."
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(
|
||||
config: pytest.Config,
|
||||
):
|
||||
# opts: Namespace = config.option
|
||||
# print(
|
||||
# f'PYTEST_CONFIGURE\n'
|
||||
# f'capture={opts.capture!r}\n'
|
||||
# )
|
||||
# breakpoint()
|
||||
|
||||
backend: str = config.option.spawn_backend
|
||||
from tractor.spawn._spawn import try_set_start_method
|
||||
try_set_start_method(backend)
|
||||
try:
|
||||
try_set_start_method(backend)
|
||||
except RuntimeError as err:
|
||||
# e.g. `--spawn-backend=subint` on Python < 3.14 — turn the
|
||||
# runtime gate error into a clean pytest usage error so the
|
||||
# suite exits with a helpful banner instead of a traceback.
|
||||
raise pytest.UsageError(str(err)) from err
|
||||
|
||||
# register custom marks to avoid warnings see,
|
||||
# https://docs.pytest.org/en/stable/how-to/writing_plugins.html#registering-custom-markers
|
||||
|
|
@ -235,10 +483,139 @@ def pytest_configure(config):
|
|||
'markers',
|
||||
'no_tpt(proto_key): test will (likely) not behave with tpt backend'
|
||||
)
|
||||
config.addinivalue_line(
|
||||
'markers',
|
||||
'skipon_spawn_backend(*start_methods, reason=None): '
|
||||
'skip this test under any of the given `--spawn-backend` '
|
||||
'values; useful for backend-specific known-hang / -borked '
|
||||
'cases (e.g. the `subint` GIL-starvation class documented '
|
||||
'in `ai/conc-anal/subint_sigint_starvation_issue.md`).'
|
||||
)
|
||||
|
||||
# `--enable-stackscope`: install SIGUSR1 → trio task-tree
|
||||
# dump in pytest itself + propagate to every subactor via
|
||||
# an env var that fork-children inherit and the runtime
|
||||
# gate honors. Lighter than `--tpdb` (no pdb machinery) —
|
||||
# purely for hang-investigation stack visibility.
|
||||
if getattr(
|
||||
config.option,
|
||||
'enable_stackscope',
|
||||
False
|
||||
):
|
||||
# Env var inherited via fork → subactor's runtime
|
||||
# picks it up at `Actor.async_main` startup. See the
|
||||
# gate in `tractor.runtime._runtime` matching this
|
||||
# var name.
|
||||
os.environ['TRACTOR_ENABLE_STACKSCOPE'] = '1'
|
||||
|
||||
# Install in pytest itself so `kill -USR1 <pytest>`
|
||||
# dumps the parent trio task-tree (which is where
|
||||
# most Mode-A-class hangs park).
|
||||
try:
|
||||
from tractor.devx._stackscope import (
|
||||
enable_stack_on_sig,
|
||||
)
|
||||
enable_stack_on_sig()
|
||||
except ImportError:
|
||||
warnings.warn(
|
||||
'`stackscope` not installed — '
|
||||
'--enable-stackscope is a no-op. '
|
||||
'Install via the `devx` dep group.'
|
||||
)
|
||||
else:
|
||||
os.environ.pop('TRACTOR_ENABLE_STACKSCOPE', None)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(
|
||||
config: pytest.Config,
|
||||
items: list[pytest.Function],
|
||||
):
|
||||
'''
|
||||
Expand any `@pytest.mark.skipon_spawn_backend('<backend>'[,
|
||||
...], reason='...')` markers into concrete
|
||||
`pytest.mark.skip(reason=...)` calls for tests whose
|
||||
backend-arg set contains the active `--spawn-backend`.
|
||||
|
||||
Uses `item.iter_markers(name=...)` which walks function +
|
||||
class + module-level marks in the correct scope order (and
|
||||
handles both the single-`MarkDecorator` and `list[Mark]`
|
||||
forms of a module-level `pytestmark`) — so the same marker
|
||||
works at any level a user puts it.
|
||||
|
||||
'''
|
||||
backend: str = config.option.spawn_backend
|
||||
default_reason: str = f'Borked on --spawn-backend={backend!r}'
|
||||
for item in items:
|
||||
for mark in item.iter_markers(name='skipon_spawn_backend'):
|
||||
skip_backends: tuple[str] = mark.args
|
||||
for skip_backend in skip_backends:
|
||||
assert (
|
||||
skip_backend in get_args(SpawnMethodKey)
|
||||
or
|
||||
skip_backend in _IN_DEV_SPAWN_BACKENDS
|
||||
)
|
||||
# ?TODO, run these through the try-set-backend checker to
|
||||
# avoid typos?
|
||||
if backend in skip_backends:
|
||||
reason: str = mark.kwargs.get(
|
||||
'reason',
|
||||
default_reason,
|
||||
)
|
||||
item.add_marker(pytest.mark.skip(reason=reason))
|
||||
# first matching mark wins; no value in stacking
|
||||
# multiple `skip`s on the same item.
|
||||
break
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
scope="session",
|
||||
autouse=True,
|
||||
)
|
||||
def alert_on_finish():
|
||||
'''
|
||||
Ring a terminal notification on full test session
|
||||
completion to alert any would be human.
|
||||
|
||||
'''
|
||||
# TODO, check attached to tty or skip!
|
||||
yield # run all tests
|
||||
print("\a") # trigger terminal bell
|
||||
# ?TODO, any other nice-tricks/specific tuis we could try?
|
||||
# - supposedly works in many terminals:
|
||||
# >> print("\033]5;Alert: Tests Finished\a")
|
||||
# - sway/i3-nag?
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_runtime_vars():
|
||||
'''
|
||||
Per-test isolation of the process-global
|
||||
`tractor.runtime._state._runtime_vars`.
|
||||
|
||||
`open_root_actor()` writes `_enable_tpts` (and other runtime
|
||||
vars) into this module-global dict, but nothing resets it on
|
||||
actor teardown. Under the in-process `pytest` launchpad a
|
||||
uds-using test therefore leaks `_enable_tpts=['uds']` into a
|
||||
sibling tcp test, which then trips the
|
||||
`registry_addrs`×`enable_transports` proto-guard in
|
||||
`open_root_actor()` with a `ValueError`. Snapshot + restore
|
||||
around every test so no runtime-var state crosses a test
|
||||
boundary.
|
||||
|
||||
'''
|
||||
from tractor.runtime import _state
|
||||
snapshot: dict = dict(_state._runtime_vars)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_state._runtime_vars.clear()
|
||||
_state._runtime_vars.update(snapshot)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def debug_mode(request) -> bool:
|
||||
def debug_mode(
|
||||
request: pytest.FixtureRequest,
|
||||
) -> bool:
|
||||
'''
|
||||
Flag state for whether `--tpdb` (for `tractor`-py-debugger)
|
||||
was passed to the test run.
|
||||
|
|
@ -252,12 +629,145 @@ def debug_mode(request) -> bool:
|
|||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def spawn_backend(request) -> str:
|
||||
def testing_pkg_name() -> str:
|
||||
'''
|
||||
Root pkg-name of the project consuming this plugin, used to
|
||||
scope `--ll` "internal"/app-level console logging into that
|
||||
project's OWN `tractor.log.get_logger(pkg_name=<.>)` hierarchy
|
||||
— distinct from the `tractor.*` runtime hierarchy configured
|
||||
via `--tl`.
|
||||
|
||||
Defaults to `'tractor'` (so tractor's own suite treats `--ll`
|
||||
as the runtime level). Downstream projects override this from
|
||||
their `conftest.py`, eg.
|
||||
|
||||
.. code:: python
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def testing_pkg_name() -> str:
|
||||
return 'modden'
|
||||
|
||||
'''
|
||||
return 'tractor'
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
scope='session',
|
||||
autouse=True,
|
||||
)
|
||||
def loglevel(
|
||||
request: pytest.FixtureRequest,
|
||||
testing_pkg_name: str,
|
||||
) -> str|None:
|
||||
'''
|
||||
Resolve + apply the test-session console loglevels and yield
|
||||
the `tractor`-runtime level (also passed to
|
||||
`open_root_actor(loglevel=<.>)` by `@tractor_test`).
|
||||
|
||||
- `--tl <logspec>`: tractor-runtime level (falls back to the
|
||||
generic `--ll`); applied to the `tractor.*` logger hierarchy
|
||||
and `tractor.log._default_loglevel` via
|
||||
`tractor.log.apply_logspec()`.
|
||||
- `--ll <level>`: the consuming-project's OWN console loglevel,
|
||||
applied to its `testing_pkg_name` hierarchy when that isn't
|
||||
`tractor` itself.
|
||||
|
||||
'''
|
||||
import tractor
|
||||
orig: str = tractor.log._default_loglevel
|
||||
|
||||
ll: str|None = request.config.option.loglevel
|
||||
tl: str|None = request.config.option.tractor_loglevel
|
||||
|
||||
# tractor-runtime loglevel: explicit `--tl` wins, else fall
|
||||
# back to the generic `--ll`, else leave the lib default.
|
||||
logspec: str|None = tl if tl is not None else ll
|
||||
tractor_level: str|None = None
|
||||
if logspec is not None:
|
||||
tractor_level, _ = tractor.log.apply_logspec(
|
||||
logspec,
|
||||
default_level=ll,
|
||||
pkg_name='tractor',
|
||||
)
|
||||
if tractor_level is not None:
|
||||
tractor.log._default_loglevel = tractor_level
|
||||
|
||||
# consuming-project ("internal") console logging at the generic
|
||||
# `--ll` level, scoped to ITS OWN pkg-hierarchy (NOT `tractor.*`)
|
||||
# so downstream projects can split app-logs from runtime-logs.
|
||||
if (
|
||||
ll is not None
|
||||
and
|
||||
testing_pkg_name
|
||||
and
|
||||
testing_pkg_name != 'tractor'
|
||||
):
|
||||
tractor.log.get_console_log(
|
||||
level=ll,
|
||||
pkg_name=testing_pkg_name,
|
||||
name=testing_pkg_name,
|
||||
)
|
||||
|
||||
log = tractor.log.get_console_log(
|
||||
level=tractor_level,
|
||||
name='tractor', # <- enable root logger
|
||||
)
|
||||
log.info(
|
||||
f'Test-harness set session loglevels:\n'
|
||||
f'tractor-runtime (`--tl`/`--ll`): {tractor_level!r}\n'
|
||||
f'{testing_pkg_name!r} (`--ll`): {ll!r}\n'
|
||||
)
|
||||
yield tractor_level
|
||||
tractor.log._default_loglevel = orig
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def test_log(
|
||||
request: pytest.FixtureRequest,
|
||||
loglevel: str,
|
||||
testing_pkg_name: str,
|
||||
) -> tractor.log.StackLevelAdapter:
|
||||
'''
|
||||
Deliver a per test-module-fn logger instance for reporting from
|
||||
within actual test bodies/fixtures.
|
||||
|
||||
For example this can be handy to report certain error cases from
|
||||
exception handlers using `test_log.exception()`.
|
||||
|
||||
The logger is scoped to the consuming-project's
|
||||
`testing_pkg_name` hierarchy so downstream suites' in-test logs
|
||||
land under their own pkg, not `tractor.*`.
|
||||
|
||||
'''
|
||||
modname: str = request.function.__module__
|
||||
log = tractor.log.get_logger(
|
||||
name=modname,
|
||||
pkg_name=testing_pkg_name,
|
||||
)
|
||||
_log = tractor.log.get_console_log(
|
||||
level=loglevel,
|
||||
logger=log,
|
||||
name=modname,
|
||||
)
|
||||
_log.debug(
|
||||
f'In-test-logging requested\n'
|
||||
f'test_log.name: {log.name!r}\n'
|
||||
f'level: {loglevel!r}\n'
|
||||
)
|
||||
yield _log
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def spawn_backend(
|
||||
request: pytest.FixtureRequest,
|
||||
) -> str:
|
||||
return request.config.option.spawn_backend
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def tpt_protos(request) -> list[str]:
|
||||
def tpt_protos(
|
||||
request: pytest.FixtureRequest,
|
||||
) -> list[str]:
|
||||
|
||||
# allow quoting on CLI
|
||||
proto_keys: list[str] = [
|
||||
|
|
@ -285,7 +795,7 @@ def tpt_protos(request) -> list[str]:
|
|||
autouse=True,
|
||||
)
|
||||
def tpt_proto(
|
||||
request,
|
||||
request: pytest.FixtureRequest,
|
||||
tpt_protos: list[str],
|
||||
) -> str:
|
||||
proto_key: str = tpt_protos[0]
|
||||
|
|
@ -337,7 +847,6 @@ def pytest_generate_tests(
|
|||
metafunc: pytest.Metafunc,
|
||||
):
|
||||
spawn_backend: str = metafunc.config.option.spawn_backend
|
||||
|
||||
if not spawn_backend:
|
||||
# XXX some weird windows bug with `pytest`?
|
||||
spawn_backend = 'trio'
|
||||
|
|
@ -345,7 +854,6 @@ def pytest_generate_tests(
|
|||
# drive the valid-backend set from the canonical `Literal` so
|
||||
# adding a new spawn backend (e.g. `'subint'`) doesn't require
|
||||
# touching the harness.
|
||||
from tractor.spawn._spawn import SpawnMethodKey
|
||||
assert spawn_backend in get_args(SpawnMethodKey)
|
||||
|
||||
# NOTE: used-to-be-used-to dyanmically parametrize tests for when
|
||||
|
|
@ -356,7 +864,8 @@ def pytest_generate_tests(
|
|||
metafunc.parametrize(
|
||||
"start_method",
|
||||
[spawn_backend],
|
||||
scope='module',
|
||||
scope='session',
|
||||
ids=lambda item: f'start_method={spawn_backend}',
|
||||
)
|
||||
|
||||
# TODO, parametrize any `tpt_proto: str` declaring tests!
|
||||
|
|
@ -367,3 +876,136 @@ def pytest_generate_tests(
|
|||
# proto_tpts, # TODO, double check this list usage!
|
||||
# scope='module',
|
||||
# )
|
||||
|
||||
|
||||
def _is_forking_spawner(
|
||||
start_method: str,
|
||||
) -> bool:
|
||||
return start_method in [
|
||||
'main_thread_forkserver',
|
||||
'mp_forkserver',
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def is_forking_spawner(
|
||||
start_method: str,
|
||||
) -> bool:
|
||||
'''
|
||||
Is the `pytest` run using a `fork()`ing process spawning-backend?
|
||||
|
||||
'''
|
||||
return _is_forking_spawner(start_method)
|
||||
|
||||
|
||||
def maybe_xfail_for_spawner(
|
||||
request: pytest.FixtureRequest,
|
||||
start_method: str,
|
||||
is_forking_spawner: bool,
|
||||
) -> None:
|
||||
'''
|
||||
Fork based spawning backends cause issues with
|
||||
`pytest`'s fd-capture mechanism and can cause various
|
||||
suites to hang.
|
||||
|
||||
This helper allows skipping/xfailing from a test when
|
||||
a fork-spawn backend is being used WITHOUT
|
||||
`--capture=sys`.
|
||||
|
||||
'''
|
||||
capture_mode: str = request.config.option.capture
|
||||
# `tee-sys` is also sys-level capture (just additionally writes
|
||||
# to the original `sys.__stdout__/__stderr__`); fork-safe like
|
||||
# `sys`. Only `fd`-level capture is the deadlock pattern.
|
||||
if (
|
||||
capture_mode not in (
|
||||
'sys',
|
||||
'tee-sys',
|
||||
)
|
||||
and
|
||||
is_forking_spawner
|
||||
):
|
||||
pytest.skip(
|
||||
f'Spawner {start_method!r} requires the flag,\n'
|
||||
f'--capture=sys or --capture=tee-sys..\n'
|
||||
f'(got --capture={capture_mode!r})\n'
|
||||
)
|
||||
|
||||
|
||||
def maybe_override_capture(
|
||||
request: pytest.FixtureRequest,
|
||||
start_method: bool,
|
||||
) -> str:
|
||||
if _is_forking_spawner(start_method):
|
||||
request.getfixturevalue('capsys')
|
||||
return 'sys'
|
||||
|
||||
return request.config.option.capture
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def set_fork_aware_capture(
|
||||
request: pytest.FixtureRequest,
|
||||
start_method: str,
|
||||
) -> pytest.CaptureFixture|str:
|
||||
'''
|
||||
Force `--capture=sys` method for tests using
|
||||
a forking-spawner backend due to fd-copying issues
|
||||
which can oddly make certain tests hang/fail.
|
||||
|
||||
'''
|
||||
# Fast-path: user already passed sys-level capture
|
||||
# (`sys` or `tee-sys`) at the CLI — no override needed.
|
||||
if request.config.option.capture in (
|
||||
'sys',
|
||||
'tee-sys',
|
||||
):
|
||||
return request.config.option.capture
|
||||
|
||||
capsys: pytest.CaptureFixture = maybe_override_capture(
|
||||
request=request,
|
||||
start_method=start_method,
|
||||
)
|
||||
return capsys
|
||||
# XXX reset?
|
||||
# with capsys.disabled():
|
||||
# pass
|
||||
# return partial(
|
||||
# maybe_override_capture,
|
||||
# request=request,
|
||||
# start_method=start_method,
|
||||
# )
|
||||
|
||||
|
||||
def pytest_terminal_summary(
|
||||
terminalreporter,
|
||||
exitstatus: int,
|
||||
config: pytest.Config,
|
||||
) -> None:
|
||||
'''
|
||||
End-of-session summary: list all
|
||||
`fail_after_w_trace`/`afk_alarm_w_trace` snapshot dirs
|
||||
captured during the run so the human doesn't have to scroll
|
||||
back through captured-stderr lines to find dump paths.
|
||||
|
||||
Reads from `tractor._testing.trace._SNAPSHOT_INDEX` which is
|
||||
populated by `_do_capture_snapshot()` on each successful
|
||||
snapshot capture.
|
||||
|
||||
No-op when zero snapshots were captured (most sessions).
|
||||
|
||||
'''
|
||||
from .trace import _SNAPSHOT_INDEX
|
||||
|
||||
if not _SNAPSHOT_INDEX:
|
||||
return
|
||||
|
||||
tr = terminalreporter
|
||||
tr.write_sep('=', 'tractor hang-snapshot index')
|
||||
tr.write_line(
|
||||
f'{len(_SNAPSHOT_INDEX)} `fail_after_w_trace` / '
|
||||
f'`afk_alarm_w_trace` snapshot(s) captured this session:'
|
||||
)
|
||||
for label, path in _SNAPSHOT_INDEX:
|
||||
tr.write_line(f' {label}')
|
||||
tr.write_line(f' → {path}')
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -41,6 +41,11 @@ from .pformat import (
|
|||
pformat_caller_frame as pformat_caller_frame,
|
||||
pformat_boxed_tb as pformat_boxed_tb,
|
||||
)
|
||||
from ._debug_hangs import (
|
||||
dump_on_hang as dump_on_hang,
|
||||
track_resource_deltas as track_resource_deltas,
|
||||
resource_delta_fixture as resource_delta_fixture,
|
||||
)
|
||||
|
||||
|
||||
# TODO, move this to a new `.devx._pdbp` mod?
|
||||
|
|
|
|||
|
|
@ -0,0 +1,227 @@
|
|||
# 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/>.
|
||||
|
||||
'''
|
||||
Hang-diagnostic helpers for concurrent / multi-interpreter code.
|
||||
|
||||
Collected from the `subint` spawn backend bringup (issue #379)
|
||||
where silent test-suite hangs needed careful teardown
|
||||
instrumentation to diagnose. This module bottles up the
|
||||
techniques that actually worked so future hangs are faster
|
||||
to corner.
|
||||
|
||||
Two primitives:
|
||||
|
||||
1. `dump_on_hang()` — context manager wrapping
|
||||
`faulthandler.dump_traceback_later()` with the critical
|
||||
gotcha baked in: write the dump to a **file**, not
|
||||
`sys.stderr`. Under `pytest` (and any other output
|
||||
capturer) stderr gets swallowed and the dump is easy to
|
||||
miss — burning hours convinced you're looking at the wrong
|
||||
thing.
|
||||
|
||||
2. `track_resource_deltas()` — context manager (+ optional
|
||||
autouse-fixture factory) logging per-block deltas of
|
||||
`threading.active_count()` and — if running on py3.13+ —
|
||||
`len(_interpreters.list_all())`. Lets you quickly rule out
|
||||
leak-accumulation theories when a suite hangs more
|
||||
frequently as it progresses (if counts don't grow, it's
|
||||
not a leak; look for a race on shared cleanup instead).
|
||||
|
||||
See issue #379 / commit `26fb820` for the worked example.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
import faulthandler
|
||||
import sys
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
Callable,
|
||||
Iterator,
|
||||
)
|
||||
|
||||
try:
|
||||
import _interpreters # type: ignore
|
||||
except ImportError:
|
||||
_interpreters = None # type: ignore
|
||||
|
||||
|
||||
__all__ = [
|
||||
'dump_on_hang',
|
||||
'track_resource_deltas',
|
||||
'resource_delta_fixture',
|
||||
]
|
||||
|
||||
|
||||
@contextmanager
|
||||
def dump_on_hang(
|
||||
seconds: float = 30.0,
|
||||
*,
|
||||
path: str | Path = '/tmp/tractor_hang.dump',
|
||||
all_threads: bool = True,
|
||||
|
||||
) -> Iterator[str]:
|
||||
'''
|
||||
Arm `faulthandler` to dump all-thread tracebacks to
|
||||
`path` after `seconds` if the with-block hasn't exited.
|
||||
|
||||
*Writes to a file, not stderr* — `pytest`'s stderr
|
||||
capture silently eats stderr-destined `faulthandler`
|
||||
output, and the same happens under any framework that
|
||||
redirects file-descriptors. Pointing the dump at a real
|
||||
file sidesteps that.
|
||||
|
||||
Yields the resolved file path so it's easy to read back.
|
||||
|
||||
Example
|
||||
-------
|
||||
::
|
||||
|
||||
from tractor.devx import dump_on_hang
|
||||
|
||||
def test_hang():
|
||||
with dump_on_hang(
|
||||
seconds=15,
|
||||
path='/tmp/my_test_hang.dump',
|
||||
) as dump_path:
|
||||
trio.run(main)
|
||||
# if it hangs, inspect dump_path afterward
|
||||
|
||||
'''
|
||||
dump_path = Path(path)
|
||||
f = dump_path.open('w')
|
||||
try:
|
||||
faulthandler.dump_traceback_later(
|
||||
seconds,
|
||||
repeat=False,
|
||||
file=f,
|
||||
exit=False,
|
||||
)
|
||||
try:
|
||||
yield str(dump_path)
|
||||
finally:
|
||||
faulthandler.cancel_dump_traceback_later()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
|
||||
def _snapshot() -> tuple[int, int]:
|
||||
'''
|
||||
Return `(thread_count, subint_count)`.
|
||||
|
||||
Subint count reported as `0` on pythons lacking the
|
||||
private `_interpreters` stdlib module (i.e. py<3.13).
|
||||
|
||||
'''
|
||||
threads: int = threading.active_count()
|
||||
subints: int = (
|
||||
len(_interpreters.list_all())
|
||||
if _interpreters is not None
|
||||
else 0
|
||||
)
|
||||
return threads, subints
|
||||
|
||||
|
||||
@contextmanager
|
||||
def track_resource_deltas(
|
||||
label: str = '',
|
||||
*,
|
||||
writer: Callable[[str], None] | None = None,
|
||||
|
||||
) -> Iterator[tuple[int, int]]:
|
||||
'''
|
||||
Log `(threads, subints)` deltas across the with-block.
|
||||
|
||||
`writer` defaults to `sys.stderr.write` (+ trailing
|
||||
newline); pass a custom callable to route elsewhere
|
||||
(e.g., a log handler or an append-to-file).
|
||||
|
||||
Yields the pre-entry snapshot so callers can assert
|
||||
against the expected counts if they want.
|
||||
|
||||
Example
|
||||
-------
|
||||
::
|
||||
|
||||
from tractor.devx import track_resource_deltas
|
||||
|
||||
async def test_foo():
|
||||
with track_resource_deltas(label='test_foo'):
|
||||
async with tractor.open_nursery() as an:
|
||||
...
|
||||
|
||||
# Output:
|
||||
# test_foo: threads 2->2, subints 1->1
|
||||
|
||||
'''
|
||||
before = _snapshot()
|
||||
try:
|
||||
yield before
|
||||
finally:
|
||||
after = _snapshot()
|
||||
msg: str = (
|
||||
f'{label}: '
|
||||
f'threads {before[0]}->{after[0]}, '
|
||||
f'subints {before[1]}->{after[1]}'
|
||||
)
|
||||
if writer is None:
|
||||
sys.stderr.write(msg + '\n')
|
||||
sys.stderr.flush()
|
||||
else:
|
||||
writer(msg)
|
||||
|
||||
|
||||
def resource_delta_fixture(
|
||||
*,
|
||||
autouse: bool = True,
|
||||
writer: Callable[[str], None] | None = None,
|
||||
|
||||
) -> Callable:
|
||||
'''
|
||||
Factory returning a `pytest` fixture that wraps each test
|
||||
in `track_resource_deltas(label=<node.name>)`.
|
||||
|
||||
Usage in a `conftest.py`::
|
||||
|
||||
# tests/conftest.py
|
||||
from tractor.devx import resource_delta_fixture
|
||||
|
||||
track_resources = resource_delta_fixture()
|
||||
|
||||
or opt-in per-test::
|
||||
|
||||
track_resources = resource_delta_fixture(autouse=False)
|
||||
|
||||
def test_foo(track_resources):
|
||||
...
|
||||
|
||||
Kept as a factory (not a bare fixture) so callers control
|
||||
`autouse` / `writer` without having to subclass or patch.
|
||||
|
||||
'''
|
||||
import pytest # deferred: only needed when caller opts in
|
||||
|
||||
@pytest.fixture(autouse=autouse)
|
||||
def _track_resources(request):
|
||||
with track_resource_deltas(
|
||||
label=request.node.name,
|
||||
writer=writer,
|
||||
):
|
||||
yield
|
||||
|
||||
return _track_resources
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
# 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/>.
|
||||
|
||||
'''
|
||||
Per-actor proc-title via `py-setproctitle`.
|
||||
|
||||
Sets a stable, OS-level identifier for each `tractor` actor
|
||||
process so diag tools (`ps`, `top`, `htop`, `psutil`) and our
|
||||
own `acli.pytree`/`acli.hung_dump` can show "which actor is
|
||||
which" at a glance without needing to read full
|
||||
`/proc/<pid>/cmdline`.
|
||||
|
||||
Format:
|
||||
``<_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
|
||||
identifier shape used in tractor's logs, the `TRACTOR_AID`
|
||||
env-var, and orphan-reaper scans — one identity across
|
||||
all surfaces.
|
||||
|
||||
Optional dep: silently no-op when `setproctitle` is missing.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from tractor.runtime._runtime import Actor
|
||||
|
||||
|
||||
# `setproctitle` is an optional dep — tractor's runtime path
|
||||
# treats this as best-effort diag, so missing import is a
|
||||
# no-op rather than a hard error.
|
||||
try:
|
||||
import setproctitle as _stp
|
||||
except ImportError:
|
||||
_stp = 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.
|
||||
|
||||
Returns the title string set, or `None` if `setproctitle`
|
||||
isn't available.
|
||||
|
||||
Should be called early in the actor's process lifetime
|
||||
(after `Actor` construction, before `_trio_main`) so the
|
||||
new title is visible to OS-level tooling for the entire
|
||||
runtime.
|
||||
|
||||
'''
|
||||
if _stp is None:
|
||||
return None
|
||||
|
||||
title: str = f'{prefix}[{actor.aid.reprol()}]'
|
||||
_stp.setproctitle(title)
|
||||
return title
|
||||
|
|
@ -24,7 +24,7 @@ disjoint, parallel executing tasks in separate actors.
|
|||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
# from functools import partial
|
||||
from functools import partial
|
||||
from threading import (
|
||||
current_thread,
|
||||
Thread,
|
||||
|
|
@ -47,7 +47,9 @@ from typing import (
|
|||
import trio
|
||||
from tractor.runtime import _state
|
||||
from tractor import log as logmod
|
||||
from tractor.devx import debug
|
||||
from tractor.devx import (
|
||||
debug,
|
||||
)
|
||||
|
||||
log = logmod.get_logger()
|
||||
|
||||
|
|
@ -61,12 +63,29 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
@trio.lowlevel.disable_ki_protection
|
||||
def dump_task_tree() -> None:
|
||||
def dump_task_tree(
|
||||
write_file: bool = False,
|
||||
write_tty: bool = False,
|
||||
) -> None:
|
||||
'''
|
||||
Do a classic `stackscope.extract()` task-tree dump to console at
|
||||
`.devx()` level.
|
||||
|
||||
When `write_file`/`write_tty` are set, ALSO tee the rendered
|
||||
tree to capture-bypassing sinks so SIGUSR1 dumps remain
|
||||
visible when the parent process has captured stdio (e.g.
|
||||
pytest's default `--capture=fd`); the SIGUSR1 handler passes
|
||||
`write_file=True` for exactly this reason:
|
||||
|
||||
- `write_file` -> `/tmp/tractor-stackscope-<pid>.log`
|
||||
(append-mode) — guaranteed-readable artifact even under CI
|
||||
/ `nohup` / no-tty conditions. `tail -f` to follow.
|
||||
- `write_tty` -> `/dev/tty` if a controlling terminal is
|
||||
attached — best-effort, ignored if the device is missing
|
||||
or write fails. pytest never captures the tty.
|
||||
|
||||
'''
|
||||
import os
|
||||
import stackscope
|
||||
tree_str: str = str(
|
||||
stackscope.extract(
|
||||
|
|
@ -96,46 +115,158 @@ def dump_task_tree() -> None:
|
|||
# |_{Supervisor/Scope
|
||||
# |_[Storage/Memory/IPC-Stream/Data-Struct
|
||||
|
||||
log.devx(
|
||||
fpath: str = f'/tmp/tractor-stackscope-{os.getpid()}.log'
|
||||
from . import pformat
|
||||
actor_repr: str = pformat.nest_from_op(
|
||||
input_op='|_',
|
||||
text=f'{actor}',
|
||||
nest_prefix='|_',
|
||||
nest_indent=3,
|
||||
)
|
||||
full_dump: str = (
|
||||
f'Dumping `stackscope` tree for actor\n'
|
||||
f'(>: {actor.uid!r}\n'
|
||||
f'(>: {actor.aid.uid!r}\n'
|
||||
f' |_{mp.current_process()}\n'
|
||||
f' |_{thr}\n'
|
||||
f' |_{actor}\n'
|
||||
# TODO, use the nest_from_op
|
||||
f'{actor_repr}'
|
||||
# f' |_{actor}'
|
||||
f'\n'
|
||||
f'{sigint_handler_report}\n'
|
||||
f'signal.getsignal(SIGINT) -> {current_sigint_handler!r}\n'
|
||||
# f'\n'
|
||||
# start-of-trace-tree delimiter (mostly for testing)
|
||||
# f'------ {actor.uid!r} ------\n'
|
||||
f'\n'
|
||||
f'------ start-of-{actor.uid!r} ------\n'
|
||||
f'capture-bypass tee: {fpath}\n'
|
||||
f'(`tail -f {fpath}` to follow across signals)\n'
|
||||
f'\n'
|
||||
f'------ start-of-{actor.aid.uid!r} ------\n'
|
||||
f'|\n'
|
||||
f'{tree_str}'
|
||||
# end-of-trace-tree delimiter (mostly for testing)
|
||||
f'|\n'
|
||||
f'|_____ end-of-{actor.uid!r} ______\n'
|
||||
f'|_____ end-of-{actor.aid.uid!r} ______\n'
|
||||
)
|
||||
# TODO: can remove this right?
|
||||
# -[ ] was original code from author
|
||||
#
|
||||
# print(
|
||||
# 'DUMPING FROM PRINT\n'
|
||||
# +
|
||||
# content
|
||||
# )
|
||||
# import logging
|
||||
# try:
|
||||
# with open("/dev/tty", "w") as tty:
|
||||
# tty.write(tree_str)
|
||||
# except BaseException:
|
||||
# logging.getLogger(
|
||||
# "task_tree"
|
||||
# ).exception("Error printing task tree")
|
||||
log.devx(full_dump)
|
||||
|
||||
# NOTE, capture-bypass sinks. Pytest's default
|
||||
# `--capture=fd` swallows `log.devx()` above; the
|
||||
# following two writes guarantee the dump reaches the
|
||||
# human even when stdio is captured.
|
||||
if write_file:
|
||||
try:
|
||||
with open(fpath, 'a') as f:
|
||||
f.write(full_dump + '\n')
|
||||
except OSError:
|
||||
log.exception(
|
||||
f'Failed to tee stackscope dump to {fpath!r}'
|
||||
)
|
||||
|
||||
if write_tty:
|
||||
try:
|
||||
with open('/dev/tty', 'w') as tty:
|
||||
tty.write(full_dump + '\n')
|
||||
except OSError:
|
||||
# no controlling tty (CI / nohup / detached) —
|
||||
# silently fall through; the file sink covers it.
|
||||
pass
|
||||
|
||||
_handler_lock = RLock()
|
||||
_tree_dumped: bool = False
|
||||
|
||||
# Captured at `enable_stack_on_sig()` time when running
|
||||
# inside a trio task. `dump_tree_on_sig` uses this to
|
||||
# schedule `dump_task_tree()` ON the trio loop via
|
||||
# `token.run_sync_soon` so stackscope sees a real current
|
||||
# task and can recurse into nursery children. Without
|
||||
# it (signal handler running in a non-trio stack frame),
|
||||
# `stackscope.extract` only walks the `<init>` task and
|
||||
# misses everything inside `async_main`'s nurseries.
|
||||
_trio_token: trio.lowlevel.TrioToken|None = None
|
||||
|
||||
|
||||
def _relay_sig_to_subactors(sig: int) -> None:
|
||||
'''
|
||||
Forward `sig` to every live sub-actor's underlying
|
||||
process so each runs its own `dump_tree_on_sig`
|
||||
handler.
|
||||
|
||||
Factored out of `dump_tree_on_sig` so the
|
||||
`run_sync_soon`-deferred path can call it AFTER
|
||||
the parent's `dump_task_tree()` completes — see
|
||||
`_dump_then_relay` below for why ordering matters.
|
||||
|
||||
'''
|
||||
an: ActorNursery
|
||||
for an in _state.current_actor()._actoruid2nursery.values():
|
||||
subproc: ProcessType
|
||||
subactor: Actor
|
||||
for (
|
||||
subactor,
|
||||
subproc,
|
||||
_,
|
||||
) in an._children.values():
|
||||
log.warning(
|
||||
f'Relaying `SIGUSR1`[{sig}] to sub-actor\n'
|
||||
f'{subactor}\n'
|
||||
f' |_{subproc}\n'
|
||||
)
|
||||
# bc of course stdlib can't have a std API.. XD
|
||||
match subproc:
|
||||
case trio.Process():
|
||||
subproc.send_signal(sig)
|
||||
|
||||
case mp.Process():
|
||||
subproc._send_signal(sig)
|
||||
|
||||
|
||||
def _dump_then_relay(
|
||||
sig: int|None,
|
||||
) -> None:
|
||||
'''
|
||||
`run_sync_soon`-friendly callback: dump THIS actor's
|
||||
task tree first, THEN relay `sig` to subactors so
|
||||
their dumps can't race ahead of ours.
|
||||
|
||||
Hierarchical-ordering preservation: the legacy
|
||||
direct-call path (pre-`run_sync_soon`) ran the dump
|
||||
synchronously inside the signal handler, then
|
||||
relayed — guaranteeing parent-output-before-child
|
||||
in the multiplexed pty stream. The pure-deferred
|
||||
path (schedule dump only, relay sync from handler)
|
||||
inverts that: relay fires while the parent's
|
||||
dump is still queued, subs receive SIGUSR1 and
|
||||
schedule their own dumps, all dumps then race in
|
||||
arbitrary order through stdio.
|
||||
|
||||
Co-scheduling fixes that: by chaining relay AFTER
|
||||
`dump_task_tree()` inside the same trio-loop
|
||||
callback, parent output flushes before any sub
|
||||
receives the signal, restoring the
|
||||
parent → relay-log → sub-dump ordering humans
|
||||
expect when reading hang-investigation traces.
|
||||
|
||||
Trio prints + crashes on uncaught exceptions in
|
||||
scheduled callbacks; we swallow + log so the test
|
||||
keeps running and the user can re-trigger.
|
||||
|
||||
'''
|
||||
try:
|
||||
dump_task_tree(write_file=True)
|
||||
except BaseException:
|
||||
log.exception(
|
||||
'`dump_task_tree()` raised (scheduled via '
|
||||
'`run_sync_soon`); continuing.\n'
|
||||
)
|
||||
|
||||
if sig is None:
|
||||
return
|
||||
|
||||
try:
|
||||
_relay_sig_to_subactors(sig)
|
||||
except BaseException:
|
||||
log.exception(
|
||||
f'`_relay_sig_to_subactors({sig})` raised '
|
||||
f'(scheduled via `run_sync_soon`); continuing.\n'
|
||||
)
|
||||
|
||||
|
||||
def dump_tree_on_sig(
|
||||
sig: int,
|
||||
|
|
@ -159,16 +290,32 @@ def dump_tree_on_sig(
|
|||
'Trying to dump `stackscope` tree..\n'
|
||||
)
|
||||
try:
|
||||
dump_task_tree()
|
||||
# await actor._service_n.start_soon(
|
||||
# partial(
|
||||
# trio.to_thread.run_sync,
|
||||
# dump_task_tree,
|
||||
# )
|
||||
# )
|
||||
# trio.lowlevel.current_trio_token().run_sync_soon(
|
||||
# dump_task_tree
|
||||
# )
|
||||
# Prefer scheduling on the trio loop — runs the
|
||||
# dump from a real trio-task context so
|
||||
# `stackscope.extract(recurse_child_tasks=True)`
|
||||
# walks every nursery child instead of seeing
|
||||
# only the `<init>` task. Falls back to a direct
|
||||
# call when no token was captured (e.g. signal
|
||||
# delivered outside a trio.run).
|
||||
#
|
||||
# Co-schedule the relay-to-subs in the SAME
|
||||
# callback so parent's dump prints BEFORE any
|
||||
# sub receives SIGUSR1 — see `_dump_then_relay`
|
||||
# for the full hierarchical-ordering rationale.
|
||||
if _trio_token is not None:
|
||||
_trio_token.run_sync_soon(
|
||||
partial(
|
||||
_dump_then_relay,
|
||||
sig=sig if relay_to_subs else None,
|
||||
)
|
||||
)
|
||||
# NOTE, `_dump_then_relay` handles the relay
|
||||
# internally; bail out before the
|
||||
# direct-path relay below.
|
||||
return
|
||||
|
||||
else:
|
||||
dump_task_tree(write_file=True)
|
||||
|
||||
except RuntimeError:
|
||||
log.exception(
|
||||
|
|
@ -188,27 +335,15 @@ def dump_tree_on_sig(
|
|||
# 'Supposedly we dumped just fine..?'
|
||||
# )
|
||||
|
||||
# Direct-path relay (only reached when `_trio_token`
|
||||
# was None — the run_sync_soon path returned above
|
||||
# to let `_dump_then_relay` handle the relay
|
||||
# in-callback).
|
||||
if not relay_to_subs:
|
||||
log.devx(f'Skipping {sig!r} relay to subactors..')
|
||||
return
|
||||
|
||||
an: ActorNursery
|
||||
for an in _state.current_actor()._actoruid2nursery.values():
|
||||
subproc: ProcessType
|
||||
subactor: Actor
|
||||
for subactor, subproc, _ in an._children.values():
|
||||
log.warning(
|
||||
f'Relaying `SIGUSR1`[{sig}] to sub-actor\n'
|
||||
f'{subactor}\n'
|
||||
f' |_{subproc}\n'
|
||||
)
|
||||
|
||||
# bc of course stdlib can't have a std API.. XD
|
||||
match subproc:
|
||||
case trio.Process():
|
||||
subproc.send_signal(sig)
|
||||
|
||||
case mp.Process():
|
||||
subproc._send_signal(sig)
|
||||
_relay_sig_to_subactors(sig)
|
||||
|
||||
|
||||
def enable_stack_on_sig(
|
||||
|
|
@ -233,19 +368,50 @@ def enable_stack_on_sig(
|
|||
|
||||
'''
|
||||
try:
|
||||
import stackscope
|
||||
# NOTE, `stackscope._glue` does intentional async-gen type
|
||||
# introspection at import-time which trips
|
||||
# `RuntimeWarning: coroutine method 'asend'/'athrow' was
|
||||
# never awaited`. Benign — they only want the wrapper
|
||||
# type — but visible to users. Squelch the import-only
|
||||
# warning so SIGUSR1 setup stays quiet.
|
||||
import warnings
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
category=RuntimeWarning,
|
||||
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`
|
||||
# so SIGUSR1 dispatches the dump *onto* the trio loop
|
||||
# (full task-tree visibility). When called outside trio
|
||||
# (e.g. from `pytest_configure`), token capture fails
|
||||
# silently and `dump_tree_on_sig` falls back to the
|
||||
# direct-call path.
|
||||
global _trio_token
|
||||
try:
|
||||
_trio_token = trio.lowlevel.current_trio_token()
|
||||
except RuntimeError:
|
||||
# not in a `trio.run` — leave None; runtime can
|
||||
# re-call `enable_stack_on_sig()` later from
|
||||
# inside `async_main` to capture it.
|
||||
_trio_token = None
|
||||
|
||||
handler: Callable|int = getsignal(sig)
|
||||
if handler is dump_tree_on_sig:
|
||||
log.devx(
|
||||
'A `SIGUSR1` handler already exists?\n'
|
||||
f'|_ {handler!r}\n'
|
||||
f'(trio_token captured: {_trio_token is not None})\n'
|
||||
)
|
||||
return
|
||||
|
||||
|
|
@ -259,5 +425,6 @@ def enable_stack_on_sig(
|
|||
f'{stackscope!r}\n\n'
|
||||
f'With `SIGUSR1` handler\n'
|
||||
f'|_{dump_tree_on_sig}\n'
|
||||
f'(trio_token captured: {_trio_token is not None})\n'
|
||||
)
|
||||
return stackscope
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ class Lock:
|
|||
return (
|
||||
f'<{cls.__name__}(\n'
|
||||
f'{body}'
|
||||
')>\n\n'
|
||||
')>\n'
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -282,7 +282,7 @@ class Lock:
|
|||
):
|
||||
message += (
|
||||
'-> No new task holds the TTY lock!\n\n'
|
||||
f'{Lock.repr()}\n'
|
||||
f'{Lock.repr()}'
|
||||
)
|
||||
|
||||
elif (
|
||||
|
|
|
|||
|
|
@ -17,10 +17,20 @@
|
|||
Linux specifics, for now we are only exposing EventFD
|
||||
|
||||
'''
|
||||
import os
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import cffi
|
||||
except ImportError as ie:
|
||||
if sys.version_info >= (3, 14):
|
||||
ie.add_note(
|
||||
f'The `cffi` pkg has no 3.14 support yet.\n'
|
||||
)
|
||||
|
||||
raise ie
|
||||
|
||||
import cffi
|
||||
import trio
|
||||
|
||||
ffi = cffi.FFI()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
Utils to tame mp non-SC madeness
|
||||
|
||||
'''
|
||||
import platform
|
||||
from functools import partial
|
||||
|
||||
|
||||
def disable_mantracker():
|
||||
|
|
@ -27,49 +27,37 @@ def disable_mantracker():
|
|||
|
||||
'''
|
||||
from multiprocessing.shared_memory import SharedMemory
|
||||
from multiprocessing import (
|
||||
resource_tracker as mantracker,
|
||||
)
|
||||
|
||||
# XXX ALWAYS disable the stdlib's "resource tracker"; it prevents
|
||||
# fork backends and never was useful to us since we're SC
|
||||
# lifetime managing all allocations.
|
||||
class ManTracker(mantracker.ResourceTracker):
|
||||
def register(self, name, rtype):
|
||||
pass
|
||||
|
||||
def unregister(self, name, rtype):
|
||||
pass
|
||||
|
||||
def ensure_running(self):
|
||||
pass
|
||||
|
||||
# "know your land and know your prey"
|
||||
# https://www.dailymotion.com/video/x6ozzco
|
||||
mantracker._resource_tracker = ManTracker()
|
||||
mantracker.register = mantracker._resource_tracker.register
|
||||
mantracker.ensure_running = mantracker._resource_tracker.ensure_running
|
||||
mantracker.unregister = mantracker._resource_tracker.unregister
|
||||
mantracker.getfd = mantracker._resource_tracker.getfd
|
||||
|
||||
# 3.13+ only.. can pass `track=False` to disable
|
||||
# all the resource tracker bs.
|
||||
# https://docs.python.org/3/library/multiprocessing.shared_memory.html
|
||||
if (_py_313 := (
|
||||
platform.python_version_tuple()[:-1]
|
||||
>=
|
||||
('3', '13')
|
||||
)
|
||||
):
|
||||
from functools import partial
|
||||
return partial(
|
||||
SharedMemory,
|
||||
track=False,
|
||||
)
|
||||
|
||||
# !TODO, once we drop 3.12- we can obvi remove all this!
|
||||
else:
|
||||
from multiprocessing import (
|
||||
resource_tracker as mantracker,
|
||||
)
|
||||
|
||||
# Tell the "resource tracker" thing to fuck off.
|
||||
class ManTracker(mantracker.ResourceTracker):
|
||||
def register(self, name, rtype):
|
||||
pass
|
||||
|
||||
def unregister(self, name, rtype):
|
||||
pass
|
||||
|
||||
def ensure_running(self):
|
||||
pass
|
||||
|
||||
# "know your land and know your prey"
|
||||
# https://www.dailymotion.com/video/x6ozzco
|
||||
mantracker._resource_tracker = ManTracker()
|
||||
mantracker.register = mantracker._resource_tracker.register
|
||||
mantracker.ensure_running = mantracker._resource_tracker.ensure_running
|
||||
mantracker.unregister = mantracker._resource_tracker.unregister
|
||||
mantracker.getfd = mantracker._resource_tracker.getfd
|
||||
|
||||
# use std type verbatim
|
||||
shmT = SharedMemory
|
||||
shmT = partial(
|
||||
SharedMemory,
|
||||
track=False,
|
||||
)
|
||||
|
||||
return shmT
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ async def handle_stream_from_peer(
|
|||
uid,
|
||||
None,
|
||||
)
|
||||
if event:
|
||||
if event is not None:
|
||||
con_status_steps += (
|
||||
' -> Waking subactor spawn waiters: '
|
||||
f'{event.statistics().tasks_waiting}\n'
|
||||
|
|
@ -1122,20 +1122,32 @@ async def _serve_ipc_eps(
|
|||
)
|
||||
|
||||
finally:
|
||||
# close every endpoint INDEPENDENTLY: a close raising
|
||||
# mid-iter (e.g. UDS `os.unlink` racing concurrent reap) must
|
||||
# not strand the rest of the eps + must not skip the
|
||||
# `_shutdown.set()` below.
|
||||
if eps:
|
||||
addr: Address
|
||||
ep: Endpoint
|
||||
for addr, ep in server.epsdict().items():
|
||||
ep.close_listener()
|
||||
server._endpoints.remove(ep)
|
||||
for addr, ep in list(server.epsdict().items()):
|
||||
try:
|
||||
ep.close_listener()
|
||||
except Exception as ep_close_err:
|
||||
log.exception(
|
||||
f'Endpoint close raised, continuing teardown\n'
|
||||
f' |_{ep!r}\n'
|
||||
f' |_{ep_close_err!r}\n'
|
||||
)
|
||||
finally:
|
||||
try:
|
||||
server._endpoints.remove(ep)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# actor = _state.current_actor()
|
||||
# if actor.is_arbiter:
|
||||
# import pdbp; pdbp.set_trace()
|
||||
|
||||
# signal the server is "shutdown"/"terminated"
|
||||
# since no more active endpoints are active.
|
||||
if not server._endpoints:
|
||||
# always signal "shutdown" so `actor.cancel()` →
|
||||
# `ipc_server.wait_for_shutdown()` doesn't deadlock when an
|
||||
# endpoint close raised above.
|
||||
if server._shutdown is not None:
|
||||
server._shutdown.set()
|
||||
|
||||
@acm
|
||||
|
|
|
|||
|
|
@ -929,15 +929,26 @@ def open_shm_list(
|
|||
# "close" attached shm on actor teardown
|
||||
try:
|
||||
actor = tractor.current_actor()
|
||||
|
||||
actor.lifetime_stack.callback(shml.shm.close)
|
||||
|
||||
# XXX on 3.13+ we don't need to call this?
|
||||
# -> bc we pass `track=False` for `SharedMemeory` orr?
|
||||
if (
|
||||
platform.python_version_tuple()[:-1] < ('3', '13')
|
||||
):
|
||||
actor.lifetime_stack.callback(shml.shm.unlink)
|
||||
# >XXX NOTE< on 3.13+ we need to call this AS WELL AS pass
|
||||
# `track=False` for `mp.SharedMemeory` otherwise fork based
|
||||
# backends will error out due to long lived stdlib
|
||||
# limitations,
|
||||
# - https://bugs.python.org/issue38119
|
||||
# - https://bugs.python.org/issue45209
|
||||
#
|
||||
def try_unlink():
|
||||
try:
|
||||
shml.shm.unlink()
|
||||
except FileNotFoundError as fne:
|
||||
log.debug(
|
||||
f'ShmList already deallocated pre-actor-shutdown.\n'
|
||||
f'{fne!r}\n'
|
||||
)
|
||||
|
||||
actor.lifetime_stack.callback(try_unlink)
|
||||
|
||||
except RuntimeError:
|
||||
log.warning('tractor runtime not active, skipping teardown steps')
|
||||
|
||||
|
|
|
|||
|
|
@ -344,7 +344,18 @@ def close_listener(
|
|||
|
||||
'''
|
||||
lstnr.socket.close()
|
||||
os.unlink(addr.sockpath)
|
||||
# tolerate the sock-file being already gone — under concurrent
|
||||
# pytest sessions sharing the bindspace dir, another session's
|
||||
# reap path can unlink it first; raising here aborts the
|
||||
# `_serve_ipc_eps` finally before `_shutdown.set()`, deadlocking
|
||||
# `wait_for_shutdown()` on `actor.cancel()`.
|
||||
try:
|
||||
os.unlink(addr.sockpath)
|
||||
except FileNotFoundError:
|
||||
log.warning(
|
||||
f'UDS sock-file already unlinked, skipping\n'
|
||||
f' |_{addr.sockpath}\n'
|
||||
)
|
||||
|
||||
|
||||
async def open_unix_socket_w_passcred(
|
||||
|
|
|
|||
270
tractor/log.py
270
tractor/log.py
|
|
@ -262,6 +262,63 @@ class StackLevelAdapter(LoggerAdapter):
|
|||
)
|
||||
|
||||
|
||||
def add_log_level(
|
||||
name: str,
|
||||
value: int,
|
||||
color: str = 'white',
|
||||
) -> None:
|
||||
'''
|
||||
Register a new custom log level with `tractor`'s logging
|
||||
machinery in ONE call — the single pluggable entry-point that
|
||||
keeps the (otherwise hand-synced) pieces consistent:
|
||||
|
||||
- `CUSTOM_LEVELS[name]` (drives the `stacklevel` bump in
|
||||
`StackLevelAdapter.log()` + the `get_logger()` audit).
|
||||
- `logging.addLevelName()` registration.
|
||||
- `STD_PALETTE`/`BOLD_PALETTE` color entries (consumed when
|
||||
`get_console_log()` builds its `ColoredFormatter`).
|
||||
- a same-named (lowercase) emit method bound on
|
||||
`StackLevelAdapter` so `log.<name>('msg')` works (and so
|
||||
`get_logger()`'s per-level method audit passes).
|
||||
|
||||
Idempotent: re-registering an existing name is a no-op-ish
|
||||
refresh (won't clobber an already-bound method).
|
||||
|
||||
'''
|
||||
name_up: str = name.upper()
|
||||
name_lo: str = name.lower()
|
||||
|
||||
CUSTOM_LEVELS[name_up] = value
|
||||
logging.addLevelName(value, name_up)
|
||||
STD_PALETTE[name_up] = color
|
||||
BOLD_PALETTE['bold'][name_up] = f'bold_{color}'
|
||||
|
||||
if not hasattr(StackLevelAdapter, name_lo):
|
||||
# bind via default-arg so `value` is captured (not
|
||||
# late-bound); delegates to `.log()` exactly like the
|
||||
# hand-written level methods above.
|
||||
def _emit(
|
||||
self,
|
||||
msg: str,
|
||||
*,
|
||||
_level: int = value,
|
||||
) -> None:
|
||||
return self.log(_level, msg)
|
||||
|
||||
_emit.__name__ = name_lo
|
||||
_emit.__qualname__ = f'StackLevelAdapter.{name_lo}'
|
||||
setattr(StackLevelAdapter, name_lo, _emit)
|
||||
|
||||
|
||||
# `IO`: child-subproc std-stream relay (see
|
||||
# `tractor.trionics._subproc`). Value 21 sits just ABOVE
|
||||
# `INFO`(20) so it's SHOWN BY DEFAULT at the usual `info`/`devx`
|
||||
# console levels (a `runtime`(15) relay would be silently
|
||||
# filtered) yet still distinctly labelled/colored + separately
|
||||
# filterable.
|
||||
add_log_level('IO', 21, 'purple')
|
||||
|
||||
|
||||
# TODO IDEAs:
|
||||
# -[ ] move to `.devx.pformat`?
|
||||
# -[ ] do per task-name and actor-name color coding
|
||||
|
|
@ -543,21 +600,45 @@ def get_logger(
|
|||
# only includes the first 2 sub-pkg name-tokens in the
|
||||
# child-logger's name; the colored "pkg-namespace" header
|
||||
# will then correctly show the same value as `name`.
|
||||
#
|
||||
# XXX, strip the trailing `pkg_path` token ONLY when it
|
||||
# duplicates the caller's leaf-*module* name — which the
|
||||
# console header already renders via its `{filename}` field.
|
||||
# We compare against the caller module's `__name__`/
|
||||
# `__package__` (rather than blindly dropping the last token)
|
||||
# so genuine, possibly-*nested* sub-PACKAGE components stay
|
||||
# addressable as their own sub-loggers:
|
||||
#
|
||||
# - `name='trionics._broadcast'` (a leaf-module, from a
|
||||
# `get_logger(__name__)`-style call) -> `tractor.trionics`
|
||||
# (leaf dropped; `_broadcast.py` is in the header).
|
||||
# - `name='devx.debug'` (a real sub-PACKAGE, whether
|
||||
# auto-derived from a module's `__package__` or passed
|
||||
# explicitly by a logging-spec) -> `tractor.devx.debug`,
|
||||
# DISTINCT from a bare `devx` -> `tractor.devx`.
|
||||
#
|
||||
# The previous unconditional `pkg_path = subpkg_path` also ate
|
||||
# the deepest sub-pkg, collapsing `devx.debug` -> `tractor.devx`
|
||||
# and silently breaking per-sub-pkg level control via the
|
||||
# logging-spec; see `tractor.log.LogSpec`/`apply_logspec()`.
|
||||
caller_leaf_mod: str|None = None
|
||||
if (caller_mod := get_caller_mod()):
|
||||
cmod_name: str = getattr(caller_mod, '__name__', '') or ''
|
||||
cmod_pkg: str = getattr(caller_mod, '__package__', '') or ''
|
||||
# a leaf-*module* has `__name__ != __package__`; a package
|
||||
# `__init__` has them equal (so its trailing token is a
|
||||
# real sub-pkg, NOT a leaf-module-filename to strip).
|
||||
if cmod_name and cmod_name != cmod_pkg:
|
||||
caller_leaf_mod = cmod_name.rpartition('.')[2]
|
||||
|
||||
if (
|
||||
# XXX, TRY to remove duplication cases
|
||||
# which get warn-logged on below!
|
||||
(
|
||||
# when, subpkg_path == pkg_path
|
||||
subpkg_path
|
||||
and
|
||||
rname == pkg_name
|
||||
)
|
||||
# ) or (
|
||||
# # when, pkg_path == leaf_mod
|
||||
# pkg_path
|
||||
# and
|
||||
# leaf_mod == pkg_path
|
||||
# )
|
||||
subpkg_path
|
||||
and
|
||||
rname == pkg_name
|
||||
and
|
||||
# only collapse when the trailing token IS the caller's
|
||||
# leaf-module (i.e. the `{filename}` already shows it).
|
||||
leaf_mod == caller_leaf_mod
|
||||
):
|
||||
pkg_path = subpkg_path
|
||||
|
||||
|
|
@ -711,6 +792,167 @@ def get_console_log(
|
|||
return log
|
||||
|
||||
|
||||
# A `tractor` "logging-spec": a compact, code-free way for a
|
||||
# consuming project's test-iface (or runtime) to dial-in console
|
||||
# loglevels across the lib's logger hierarchy. Mirrors the grammar
|
||||
# consumed by `modden.runtime.daemon.setup_tractor_logging()`.
|
||||
#
|
||||
# Accepted forms (`str|bool`),
|
||||
# - `True` -> enable the `pkg_name` root-logger at
|
||||
# `default_level` (or 'cancel').
|
||||
# - `False` -> disable (no-op, configure nothing).
|
||||
# - 'info' -> a bare level for the root-logger.
|
||||
# - 'sub:info,x:cancel' -> per-sub-logger levels; each `<name>` is
|
||||
# RELATIVE to `pkg_name` (must NOT include
|
||||
# the `pkg_name` token itself), eg.
|
||||
# 'devx.debug:runtime,trionics:cancel'.
|
||||
#
|
||||
# !GRANULARITY! sub-logger names match at the `pkg_name.<name>`
|
||||
# *logger* level — which (per `get_logger()`'s name-derivation) is
|
||||
# *sub-PACKAGE* granularity, addressable at ANY nesting depth:
|
||||
# - 'devx.debug' -> the `tractor.devx.debug` logger, DISTINCT from a
|
||||
# bare 'devx' -> `tractor.devx` (its parent). Setting `devx` also
|
||||
# gates `devx.debug` via normal stdlib level-inheritance unless the
|
||||
# child sets its own level.
|
||||
# - leaf *modules* are intentionally NOT individually addressable:
|
||||
# `get_logger()` drops the leaf module-name from the logger key
|
||||
# since the console header already renders it via `{filename}`, so
|
||||
# every module in a (sub-)pkg shares that pkg's logger. Per-leaf
|
||||
# level control would need a record-filter (see follow-up notes:
|
||||
# `ai/tooling-todos/logspec_leaf_module_granularity_route_b.md`).
|
||||
# - top-level lib modules (eg. `tractor.to_asyncio`) emit under the
|
||||
# *root* `pkg_name` logger (their `__package__` IS `pkg_name`), so
|
||||
# a 'to_asyncio:<level>' entry targets a phantom child that nothing
|
||||
# emits to -> no-op. Use the bare-level/root form for those.
|
||||
LogSpec = str|bool
|
||||
|
||||
|
||||
def parse_logspec(
|
||||
logspec: LogSpec,
|
||||
default_level: str|None = None,
|
||||
pkg_name: str = _proj_name,
|
||||
|
||||
) -> dict[str|None, str]:
|
||||
'''
|
||||
Parse a `tractor` "logging-spec" (see `LogSpec`) into a
|
||||
`{sublog_name|None: level}` mapping where a `None` key denotes
|
||||
the `pkg_name` root-logger itself.
|
||||
|
||||
'''
|
||||
match logspec:
|
||||
|
||||
# explicit disable -> configure nothing.
|
||||
case False:
|
||||
return {}
|
||||
|
||||
# enable the root-logger at the fallback level.
|
||||
case True:
|
||||
return {None: (default_level or 'cancel')}
|
||||
|
||||
case str(spec):
|
||||
filters: list[str] = [
|
||||
part.strip()
|
||||
for part in spec.split(',')
|
||||
if part.strip()
|
||||
]
|
||||
# i. a bare level (no sub-logger filtering),
|
||||
# eg. 'info' | 'cancel'
|
||||
if (
|
||||
len(filters) == 1
|
||||
and
|
||||
':' not in filters[0]
|
||||
):
|
||||
return {None: filters[0]}
|
||||
|
||||
# ii. a per-sub-logger filter-spec of the form,
|
||||
# '<sublog_0>:<level>,<.. N-other-parts>'
|
||||
# eg. 'to_asyncio:cancel,devx._debug:runtime'
|
||||
out: dict[str|None, str] = {}
|
||||
for log_filter in filters:
|
||||
name, sep, level = log_filter.partition(':')
|
||||
if not sep:
|
||||
raise ValueError(
|
||||
f'Invalid `tractor` logging-spec part!\n'
|
||||
f'{log_filter!r}\n'
|
||||
f'\n'
|
||||
f'Mixed bare-level + sub-logger filters are '
|
||||
f'not supported; every comma-part must be '
|
||||
f'`<sublog>:<level>`.\n'
|
||||
)
|
||||
# the sub-logger name is RELATIVE to `pkg_name`;
|
||||
# duplicating the pkg-token is a user error since
|
||||
# the root-logger already IS `pkg_name`.
|
||||
if pkg_name in name.split('.'):
|
||||
raise ValueError(
|
||||
f'logging-spec sub-name should NOT include '
|
||||
f'the `pkg_name={pkg_name!r}` token!\n'
|
||||
f'got name={name!r}\n'
|
||||
)
|
||||
out[name] = level
|
||||
return out
|
||||
|
||||
case _:
|
||||
raise ValueError(
|
||||
f'Invalid `tractor` logging-spec!\n'
|
||||
f'{logspec!r}\n'
|
||||
)
|
||||
|
||||
|
||||
def apply_logspec(
|
||||
logspec: LogSpec,
|
||||
default_level: str|None = None,
|
||||
pkg_name: str = _proj_name,
|
||||
|
||||
) -> tuple[
|
||||
str|None,
|
||||
dict[str, StackLevelAdapter],
|
||||
]:
|
||||
'''
|
||||
Parse + apply a `tractor` "logging-spec" (see `parse_logspec()`):
|
||||
enable a `colorlog` stderr console handler for each
|
||||
(sub-)logger named in the spec at its requested level.
|
||||
|
||||
Returns a 2-tuple,
|
||||
- the resolved "primary" runtime-level: the root-logger level if
|
||||
the spec set one, else `default_level`; suitable for passing
|
||||
to `open_root_actor(loglevel=<.>)`,
|
||||
- a `{logger_name: StackLevelAdapter}` map of every logger the
|
||||
spec touched.
|
||||
|
||||
'''
|
||||
specs: dict[str|None, str] = parse_logspec(
|
||||
logspec,
|
||||
default_level=default_level,
|
||||
pkg_name=pkg_name,
|
||||
)
|
||||
logs: dict[str, StackLevelAdapter] = {}
|
||||
for sub_name, level in specs.items():
|
||||
# NOTE, pass the RELATIVE sub-name (no `pkg_name.` prefix)
|
||||
# to avoid `get_logger()`'s duplicate-pkg-token warning;
|
||||
# it re-adds the pkg-name via `.getChild()` internally.
|
||||
log: StackLevelAdapter = get_console_log(
|
||||
level=level,
|
||||
pkg_name=pkg_name,
|
||||
name=(sub_name or pkg_name),
|
||||
)
|
||||
# XXX, a sub-logger filter is "authoritative" for its
|
||||
# subtree: it gets its OWN stderr handler (added by
|
||||
# `get_console_log()` above), so DON'T also let its records
|
||||
# propagate up to a root `pkg_name`-logger handler — that
|
||||
# would double-emit every line when a root-level console
|
||||
# (eg. via `--ll`) is also active. The root-level form
|
||||
# (`sub_name is None`) keeps default propagation.
|
||||
if sub_name is not None:
|
||||
log.logger.propagate = False
|
||||
logs[log.name] = log
|
||||
|
||||
primary_level: str|None = specs.get(None, default_level)
|
||||
return (
|
||||
primary_level,
|
||||
logs,
|
||||
)
|
||||
|
||||
|
||||
def get_loglevel() -> str:
|
||||
return _default_loglevel
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ from ..msg import (
|
|||
Return,
|
||||
)
|
||||
from .._exceptions import (
|
||||
ActorTooSlowError,
|
||||
NoResult,
|
||||
TransportClosed,
|
||||
)
|
||||
|
|
@ -268,6 +269,7 @@ class Portal:
|
|||
async def cancel_actor(
|
||||
self,
|
||||
timeout: float | None = None,
|
||||
raise_on_timeout: bool = False,
|
||||
|
||||
) -> bool:
|
||||
'''
|
||||
|
|
@ -281,6 +283,17 @@ class Portal:
|
|||
`._context.Context.cancel()` which CAN be used for this
|
||||
purpose.
|
||||
|
||||
`raise_on_timeout` (default `False`):
|
||||
|
||||
- `False` (legacy): on bounded-wait expiry, log at DEBUG
|
||||
and return `False`. Used by callers that issue cancel
|
||||
fire-and-forget and have their own escalation
|
||||
(e.g. `_spawn.soft_kill()` checks `proc.poll()` after).
|
||||
- `True`: on bounded-wait expiry, raise `ActorTooSlowError`
|
||||
so the caller MUST handle the failure explicitly.
|
||||
`ActorNursery.cancel()` opts in so it can escalate via
|
||||
`proc.terminate()` per SC-discipline.
|
||||
|
||||
'''
|
||||
__runtimeframe__: int = 1 # noqa
|
||||
|
||||
|
|
@ -301,15 +314,16 @@ class Portal:
|
|||
|
||||
# XXX the one spot we set it?
|
||||
chan._cancel_called: bool = True
|
||||
cancel_timeout: float = (
|
||||
timeout
|
||||
or
|
||||
self.cancel_timeout
|
||||
)
|
||||
try:
|
||||
# send cancel cmd - might not get response
|
||||
# XXX: sure would be nice to make this work with
|
||||
# a proper shield
|
||||
with trio.move_on_after(
|
||||
timeout
|
||||
or
|
||||
self.cancel_timeout
|
||||
) as cs:
|
||||
with trio.move_on_after(cancel_timeout) as cs:
|
||||
cs.shield: bool = True
|
||||
await self.run_from_ns(
|
||||
'self',
|
||||
|
|
@ -317,16 +331,32 @@ class Portal:
|
|||
)
|
||||
return True
|
||||
|
||||
if cs.cancelled_caught:
|
||||
# may timeout and we never get an ack (obvi racy)
|
||||
# but that doesn't mean it wasn't cancelled.
|
||||
log.debug(
|
||||
f'May have failed to cancel peer?\n'
|
||||
f'\n'
|
||||
f'c)=?> {peer_id}\n'
|
||||
# `move_on_after` fired — peer didn't ack within
|
||||
# bounded window. Behaviour depends on
|
||||
# `raise_on_timeout`:
|
||||
if (
|
||||
cs.cancelled_caught
|
||||
and
|
||||
raise_on_timeout
|
||||
):
|
||||
raise ActorTooSlowError(
|
||||
f'Peer {peer_id} did not ack its '
|
||||
f'`Actor.cancel()` RPC within bounded wait '
|
||||
f'of {cancel_timeout!r}s'
|
||||
)
|
||||
|
||||
# if we get here some weird cancellation case happened
|
||||
# legacy fire-and-forget path: log + return False so
|
||||
# the caller can decide whether to escalate.
|
||||
#
|
||||
# NOTE, we also land here in the (unexpected) case where
|
||||
# the shielded `move_on_after` block exits WITHOUT
|
||||
# `return True` and WITHOUT the deadline firing — prefer
|
||||
# a soft `False` over an `assert`-crash mid-teardown.
|
||||
log.debug(
|
||||
f'May have failed to cancel peer?\n'
|
||||
f'\n'
|
||||
f'c)=?> {peer_id}\n'
|
||||
)
|
||||
return False
|
||||
|
||||
except TransportClosed as tpt_err:
|
||||
|
|
|
|||
|
|
@ -870,7 +870,14 @@ class Actor:
|
|||
|
||||
accept_addrs: list[UnwrappedAddress]|None = None
|
||||
|
||||
if self._spawn_method == "trio":
|
||||
if self._spawn_method in (
|
||||
'trio',
|
||||
'subint',
|
||||
# `subint_forkserver` parent-side sends a
|
||||
# `SpawnSpec` over IPC just like the other two
|
||||
# — fork child-side runtime is trio-native.
|
||||
'subint_forkserver',
|
||||
):
|
||||
|
||||
# Receive post-spawn runtime state from our parent.
|
||||
spawnspec: msgtypes.SpawnSpec = await chan.recv()
|
||||
|
|
@ -922,11 +929,29 @@ class Actor:
|
|||
# => update process-wide globals
|
||||
# TODO! -[ ] another `Struct` for rtvs..
|
||||
rvs: dict[str, Any] = spawnspec._runtime_vars
|
||||
if rvs['_debug_mode']:
|
||||
from ..devx import (
|
||||
enable_stack_on_sig,
|
||||
maybe_init_greenback,
|
||||
)
|
||||
|
||||
# `stackscope` SIGUSR1 handler: install when ANY of
|
||||
# `_debug_mode` / `use_stackscope` rt-vars OR the
|
||||
# `TRACTOR_ENABLE_STACKSCOPE` env var is set (the
|
||||
# latter being a lighter test-time hang-debug path;
|
||||
# see `tractor._testing.pytest`'s `--enable-stackscope`
|
||||
# CLI flag — env var propagates via fork-inherited
|
||||
# environ).
|
||||
#
|
||||
# NOTE, NOT *exclusively* gated on `_debug_mode` so
|
||||
# SIGUSR1 task-tree dumps work in plain (non-pdb)
|
||||
# runs too — but we DO still install under
|
||||
# `_debug_mode` since otherwise the default SIGUSR1
|
||||
# action would terminate the proc, esp. nasty in
|
||||
# infected-`asyncio` sub-actors mid-REPL.
|
||||
if (
|
||||
rvs.get('_debug_mode')
|
||||
or
|
||||
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`
|
||||
|
|
@ -938,10 +963,13 @@ class Actor:
|
|||
|
||||
except ImportError:
|
||||
log.warning(
|
||||
'`stackscope` not installed for use in debug mode!'
|
||||
'`stackscope` not installed for use in '
|
||||
'debug mode / `--enable-stackscope`!'
|
||||
)
|
||||
|
||||
if rvs['_debug_mode']:
|
||||
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(
|
||||
|
|
@ -1209,6 +1237,23 @@ class Actor:
|
|||
ipc_server.cancel()
|
||||
await ipc_server.wait_for_shutdown()
|
||||
|
||||
# Break the shield on the parent-channel
|
||||
# `process_messages` loop (started with `shield=True`
|
||||
# in `async_main` above). Required to avoid a
|
||||
# deadlock during teardown of fork-spawned subactors:
|
||||
# without this cancel, the loop parks waiting for
|
||||
# EOF on the parent channel, but the parent is
|
||||
# blocked on `os.waitpid()` for THIS actor's exit
|
||||
# — mutual wait. For exec-spawn backends the EOF
|
||||
# arrives naturally when the parent closes its
|
||||
# handler-task socket during its own teardown, but
|
||||
# in fork backends the shared-process-image makes
|
||||
# that delivery racy / not guaranteed. Explicit
|
||||
# cancel here gives us deterministic unwinding
|
||||
# regardless of backend.
|
||||
if self._parent_chan_cs is not None:
|
||||
self._parent_chan_cs.cancel()
|
||||
|
||||
# cancel all rpc tasks permanently
|
||||
if self._service_tn:
|
||||
self._service_tn.cancel_scope.cancel()
|
||||
|
|
@ -1729,7 +1774,16 @@ async def async_main(
|
|||
# start processing parent requests until our channel
|
||||
# server is 100% up and running.
|
||||
if actor._parent_chan:
|
||||
await root_tn.start(
|
||||
# Capture the shielded `loop_cs` for the
|
||||
# parent-channel `process_messages` task so
|
||||
# `Actor.cancel()` has a handle to break the
|
||||
# shield during teardown — without this, the
|
||||
# shielded loop would park on the parent chan
|
||||
# indefinitely waiting for EOF that only arrives
|
||||
# after the PARENT tears down, which under
|
||||
# fork-based backends (e.g. `main_thread_forkserver`)
|
||||
# it waits on THIS actor's exit — deadlock.
|
||||
actor._parent_chan_cs = await root_tn.start(
|
||||
partial(
|
||||
_rpc.process_messages,
|
||||
chan=actor._parent_chan,
|
||||
|
|
@ -1940,7 +1994,25 @@ async def async_main(
|
|||
f' {pformat(ipc_server._peers)}'
|
||||
)
|
||||
log.runtime(teardown_report)
|
||||
await ipc_server.wait_for_no_more_peers()
|
||||
# NOTE: bound the peer-clear wait — otherwise if any
|
||||
# peer-channel handler is stuck (e.g. never got its
|
||||
# cancel propagated due to a runtime bug), this wait
|
||||
# blocks forever and deadlocks the whole actor-tree
|
||||
# teardown cascade. 3s is enough for any graceful
|
||||
# cancel-ack round-trip; beyond that we're in bug
|
||||
# territory and need to proceed with local teardown
|
||||
# so the parent's `_ForkedProc.wait()` can unblock.
|
||||
# See `ai/conc-anal/
|
||||
# subint_forkserver_test_cancellation_leak_issue.md`
|
||||
# for the full diagnosis.
|
||||
with trio.move_on_after(3.0) as _peers_cs:
|
||||
await ipc_server.wait_for_no_more_peers()
|
||||
if _peers_cs.cancelled_caught:
|
||||
teardown_report += (
|
||||
f'-> TIMED OUT waiting for peers to clear '
|
||||
f'({len(ipc_server._peers)} still connected)\n'
|
||||
)
|
||||
log.warning(teardown_report)
|
||||
|
||||
teardown_report += (
|
||||
'-]> all peer channels are complete.\n'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -102,7 +103,6 @@ class RuntimeVars(Struct):
|
|||
key,
|
||||
val,
|
||||
) -> None:
|
||||
breakpoint()
|
||||
super().__setattr__(key, val)
|
||||
|
||||
def update(
|
||||
|
|
@ -117,7 +117,14 @@ class RuntimeVars(Struct):
|
|||
)
|
||||
|
||||
|
||||
_runtime_vars: dict[str, Any] = {
|
||||
# The "fresh process" defaults — what `_runtime_vars` looks
|
||||
# like in a just-booted Python process that hasn't yet entered
|
||||
# `open_root_actor()` nor received a parent `SpawnSpec`. Kept
|
||||
# as a module-level constant so `get_runtime_vars(clear_values=
|
||||
# True)` can reset the live dict back to this baseline (see
|
||||
# `tractor.spawn._main_thread_forkserver` for the one current
|
||||
# caller that needs it).
|
||||
_RUNTIME_VARS_DEFAULTS: dict[str, Any] = {
|
||||
# root of actor-process tree info
|
||||
'_is_root': False, # bool
|
||||
'_root_mailbox': (None, None), # tuple[str|None, str|None]
|
||||
|
|
@ -132,16 +139,19 @@ _runtime_vars: 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,
|
||||
}
|
||||
_runtime_vars: dict[str, Any] = dict(_RUNTIME_VARS_DEFAULTS)
|
||||
|
||||
|
||||
def get_runtime_vars(
|
||||
as_dict: bool = True,
|
||||
clear_values: bool = False,
|
||||
) -> dict:
|
||||
'''
|
||||
Deliver a **copy** of the current `Actor`'s "runtime variables".
|
||||
|
|
@ -150,11 +160,62 @@ def get_runtime_vars(
|
|||
form, but the `RuntimeVars` struct should be utilized as possible
|
||||
for future calls.
|
||||
|
||||
'''
|
||||
if as_dict:
|
||||
return dict(_runtime_vars)
|
||||
Pure read — **never mutates** the module-level `_runtime_vars`.
|
||||
|
||||
return RuntimeVars(**_runtime_vars)
|
||||
If `clear_values=True`, return a copy of the fresh-process
|
||||
defaults (`_RUNTIME_VARS_DEFAULTS`) instead of the live
|
||||
dict. Useful in combination with `set_runtime_vars()` to
|
||||
reset process-global state back to "cold" — the main caller
|
||||
today is the `main_thread_forkserver` spawn backend's post-fork
|
||||
child prelude:
|
||||
|
||||
set_runtime_vars(get_runtime_vars(clear_values=True))
|
||||
|
||||
`os.fork()` inherits the parent's full memory image, so the
|
||||
child sees the parent's populated `_runtime_vars` (e.g.
|
||||
`_is_root=True`) which would trip the `assert not
|
||||
self.enable_modules` gate in `Actor._from_parent()` on the
|
||||
subsequent parent→child `SpawnSpec` handshake if left alone.
|
||||
|
||||
'''
|
||||
src: dict = (
|
||||
_RUNTIME_VARS_DEFAULTS
|
||||
if clear_values
|
||||
else _runtime_vars
|
||||
)
|
||||
snapshot: dict = dict(src)
|
||||
if as_dict:
|
||||
return snapshot
|
||||
return RuntimeVars(**snapshot)
|
||||
|
||||
|
||||
def set_runtime_vars(
|
||||
rtvars: dict | RuntimeVars,
|
||||
) -> None:
|
||||
'''
|
||||
Atomically replace the module-level `_runtime_vars` contents
|
||||
with those of `rtvars` (via `.clear()` + `.update()` so
|
||||
live references to the same dict object remain valid).
|
||||
|
||||
Accepts either the historical `dict` form or the `RuntimeVars`
|
||||
`msgspec.Struct` form (the latter still mostly unused but
|
||||
the blessed forward shape — see the struct's definition).
|
||||
|
||||
Paired with `get_runtime_vars()` as the explicit
|
||||
write-half of the runtime-vars API — prefer this over
|
||||
direct mutation of `_runtime_vars[...]` from new call sites.
|
||||
|
||||
'''
|
||||
if isinstance(rtvars, RuntimeVars):
|
||||
# `msgspec.Struct` → dict via its declared field set;
|
||||
# avoids pulling in `msgspec.structs.asdict` just for
|
||||
# this one call path.
|
||||
rtvars = {
|
||||
field_name: getattr(rtvars, field_name)
|
||||
for field_name in rtvars.__struct_fields__
|
||||
}
|
||||
_runtime_vars.clear()
|
||||
_runtime_vars.update(rtvars)
|
||||
|
||||
|
||||
def last_actor() -> Actor|None:
|
||||
|
|
|
|||
|
|
@ -38,8 +38,14 @@ from ..discovery._addr import (
|
|||
UnwrappedAddress,
|
||||
mk_uuid,
|
||||
)
|
||||
from ._state import current_actor, is_main_process
|
||||
from ..log import get_logger, get_loglevel
|
||||
from ._state import (
|
||||
current_actor,
|
||||
is_main_process,
|
||||
)
|
||||
from ..log import (
|
||||
get_logger,
|
||||
get_loglevel,
|
||||
)
|
||||
from ._runtime import Actor
|
||||
from ._portal import Portal
|
||||
from ..trionics import (
|
||||
|
|
@ -47,6 +53,7 @@ from ..trionics import (
|
|||
collapse_eg,
|
||||
)
|
||||
from .._exceptions import (
|
||||
ActorTooSlowError,
|
||||
ContextCancelled,
|
||||
)
|
||||
from .._root import (
|
||||
|
|
@ -60,11 +67,106 @@ if TYPE_CHECKING:
|
|||
import multiprocessing as mp
|
||||
# from ..ipc._server import IPCServer
|
||||
from ..ipc import IPCServer
|
||||
from ..spawn._spawn import ProcessType
|
||||
|
||||
|
||||
log = get_logger()
|
||||
|
||||
|
||||
async def _try_cancel_then_kill(
|
||||
portal: Portal,
|
||||
# `ProcessType` is `TYPE_CHECKING`-only (defined under that
|
||||
# guard in `..spawn._spawn`) so we stringify here to avoid
|
||||
# eager runtime eval of the annotation at function-def time
|
||||
# (this module has no `from __future__ import annotations`).
|
||||
proc: 'ProcessType',
|
||||
subactor: Actor,
|
||||
debug_mode_active: bool = False,
|
||||
) -> None:
|
||||
'''
|
||||
Per-child cancel-then-escalate helper used by
|
||||
`ActorNursery.cancel()`.
|
||||
|
||||
Sends a graceful actor-runtime cancel-RPC via
|
||||
`Portal.cancel_actor(raise_on_timeout=True)`. If the bounded-wait
|
||||
expires before the peer ack's, `ActorTooSlowError` is raised and
|
||||
we escalate via `proc.terminate()` (SIGTERM) per SC-discipline:
|
||||
|
||||
graceful cancel-req -> bounded wait -> hard-kill
|
||||
|
||||
Without this escalation, a same-name sibling subactor whose
|
||||
cancel-RPC failed to ack within `Portal.cancel_timeout` (e.g.
|
||||
under TCP+forkserver register-RPC contention) would park the
|
||||
parent's `soft_kill()` watcher forever waiting on `proc.poll()`,
|
||||
deadlocking nursery `__aexit__`. See `ActorTooSlowError` for
|
||||
the wider write-up.
|
||||
|
||||
'''
|
||||
# XXX, do NOT escalate to `proc.terminate()` while ANY of
|
||||
# the following are true — SIGTERM-ing a sub would tear
|
||||
# down its sub-tree including any descendant proxying
|
||||
# stdio to/from a REPL-locked actor, clobbering the user's
|
||||
# debug session:
|
||||
#
|
||||
# - `Lock.ctx_in_debug is not None`: most precise — some
|
||||
# actor in the tree is currently REPL-locked. Set in the
|
||||
# root actor for the lifetime of the lock. Raceable
|
||||
# (false negative if SIGINT arrives before lock-acquire
|
||||
# RPC completes).
|
||||
#
|
||||
# - `_runtime_vars['_debug_mode']`: root-actor was opened
|
||||
# with `debug_mode=True` (via `open_root_actor` /
|
||||
# `open_nursery`). Set once at root boot, never cleared.
|
||||
# Catches deep-descendant REPL sessions even when the
|
||||
# intermediate nurseries didn't pass `debug_mode=` per-
|
||||
# child.
|
||||
#
|
||||
# - `debug_mode_active`: this nursery has at least one
|
||||
# child started with an explicit `debug_mode=` arg
|
||||
# (`ActorNursery._at_least_one_child_in_debug`). Catches
|
||||
# the case where root is NOT in debug-mode but a
|
||||
# nursery-direct child opted in.
|
||||
#
|
||||
# Independent because root may NOT be in debug-mode even
|
||||
# when a child is (only the child's `_runtime_vars` is
|
||||
# mutated by per-child `debug_mode=True`). ORing covers
|
||||
# every flavor without false-positively skipping
|
||||
# legitimate hard-kill paths in non-debug trees.
|
||||
if (
|
||||
debug.Lock.ctx_in_debug is not None
|
||||
or
|
||||
_state._runtime_vars.get('_debug_mode', False)
|
||||
or
|
||||
debug_mode_active
|
||||
):
|
||||
await portal.cancel_actor()
|
||||
return
|
||||
|
||||
try:
|
||||
await portal.cancel_actor(raise_on_timeout=True)
|
||||
except ActorTooSlowError as too_slow:
|
||||
log.error(
|
||||
f'Cancel-ack TIMED OUT for sub-actor\n'
|
||||
f' uid: {subactor.aid.reprol()!r}\n'
|
||||
f' reason: {too_slow}\n'
|
||||
f'-> escalating to `proc.terminate()` (hard-kill)\n'
|
||||
)
|
||||
# XXX, the `subint` backend stores an `int` interp-id in the
|
||||
# `proc` slot (not a `Process`), so it has no `.terminate()`.
|
||||
# Guard here so a cancel-ack timeout doesn't `AttributeError`
|
||||
# once that backend lands; its hard-kill path is a TODO.
|
||||
if hasattr(proc, 'terminate'):
|
||||
proc.terminate()
|
||||
else:
|
||||
log.error(
|
||||
f'Cannot hard-kill sub-actor — backend proc-handle '
|
||||
f'{proc!r} ({type(proc).__name__!r}) has no '
|
||||
f'`.terminate()`!\n'
|
||||
f' uid: {subactor.aid.reprol()!r}\n'
|
||||
f'TODO: per-backend cancel-escalation.\n'
|
||||
)
|
||||
|
||||
|
||||
class ActorNursery:
|
||||
'''
|
||||
The fundamental actor supervision construct: spawn and manage
|
||||
|
|
@ -428,10 +530,23 @@ class ActorNursery:
|
|||
else: # there's no other choice left
|
||||
proc.terminate()
|
||||
|
||||
# spawn cancel tasks for each sub-actor
|
||||
# spawn per-child cancel tasks; the helper
|
||||
# escalates to hard-kill on
|
||||
# `ActorTooSlowError` rather than silently
|
||||
# swallowing the cancel-ack timeout, EXCEPT
|
||||
# when this nursery has any debug-eligible
|
||||
# child (in which case we keep legacy
|
||||
# fire-and-forget semantics to avoid
|
||||
# clobbering an active REPL).
|
||||
assert portal
|
||||
if portal.channel.connected():
|
||||
tn.start_soon(portal.cancel_actor)
|
||||
tn.start_soon(
|
||||
_try_cancel_then_kill,
|
||||
portal,
|
||||
proc,
|
||||
subactor,
|
||||
self._at_least_one_child_in_debug,
|
||||
)
|
||||
|
||||
log.cancel(msg)
|
||||
# if we cancelled the cancel (we hung cancelling remote actors)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,183 @@
|
|||
# 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/>.
|
||||
|
||||
'''
|
||||
Post-mortem subactor cleanup primitives — things the parent
|
||||
runtime has to clean up because the dead-or-SIGKILL'd child
|
||||
couldn't.
|
||||
|
||||
Sibling of `tractor._testing._reap` which is the test-harness
|
||||
equivalent (orphan-pid + leaked-shm + leaked-UDS-sock sweeper
|
||||
fixtures). This module is the spawn-layer counterpart, called
|
||||
inline from `hard_kill` and the broader subactor reap path.
|
||||
|
||||
Today this is just `unlink_uds_bind_addrs()`. As future
|
||||
post-mortem cleanup needs surface (e.g. `/dev/shm` segment
|
||||
unlink for hard-crashed actors, leaked-pidfile cleanup), they
|
||||
land here too.
|
||||
|
||||
Future-work TODO — authoritative UDS bind-addr tracking
|
||||
-------------------------------------------------------
|
||||
|
||||
`unlink_uds_bind_addrs()` currently has two cleanup paths:
|
||||
|
||||
1. Explicit `bind_addrs` (when parent set them at spawn time)
|
||||
2. **Convention-based reconstruction** —
|
||||
`<XDG_RUNTIME_DIR>/tractor/<name>@<pid>.sock` — for the
|
||||
common case where the subactor self-assigned a random sock
|
||||
via `UDSAddress.get_random()`.
|
||||
|
||||
Path (2) hardcodes the `<name>@<pid>.sock` convention from
|
||||
`tractor.ipc._uds.UDSAddress`. If that convention ever
|
||||
changes — or the subactor binds to a non-default
|
||||
`bindspace`/`filedir` — we'll silently fail to unlink.
|
||||
|
||||
A more authoritative approach would be:
|
||||
|
||||
- Subactors register their bound UDS sockpaths in a
|
||||
per-process registry inside `tractor.ipc._uds` at
|
||||
`start_listener()` time.
|
||||
- The subactor reports its bound sockpath(s) back to the
|
||||
parent over IPC immediately post-bind (extension to
|
||||
`SpawnSpec` reply / a new handshake msg).
|
||||
- Parent caches the subactor's authoritative sockpaths.
|
||||
- `unlink_uds_bind_addrs()` checks the cache FIRST, falls
|
||||
back to convention-reconstruction if the subactor died
|
||||
before reporting (which is the SIGKILL case this fn
|
||||
primarily exists for).
|
||||
|
||||
Tracked as future work in #454 (the parent UDS-leak
|
||||
issue this module addresses); a separate issue may be
|
||||
filed if/when the registry impl is scoped.
|
||||
|
||||
See also #452 — the discovery-client `CLOSE_WAIT` TCP
|
||||
fd leak. Different bug class but same broader theme of
|
||||
"fork-spawn unmasked latent cleanup gaps".
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import trio
|
||||
|
||||
from tractor.discovery._addr import (
|
||||
UnwrappedAddress,
|
||||
wrap_address,
|
||||
)
|
||||
from tractor.ipc._uds import UDSAddress
|
||||
from tractor.log import get_logger
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from tractor.runtime._runtime import Actor
|
||||
|
||||
|
||||
log = get_logger('tractor')
|
||||
|
||||
|
||||
def unlink_uds_bind_addrs(
|
||||
proc: trio.Process,
|
||||
*,
|
||||
bind_addrs: list[UnwrappedAddress] | None = None,
|
||||
subactor: Actor | None = None,
|
||||
) -> None:
|
||||
'''
|
||||
Best-effort post-mortem cleanup of any UDS sock-files
|
||||
a hard-killed subactor was bound to.
|
||||
|
||||
SIGKILL bypasses Python execution → the subactor's
|
||||
`_serve_ipc_eps` `finally:` block (which normally calls
|
||||
`os.unlink(addr.sockpath)`) never runs. Without this
|
||||
parent-side cleanup, the dead subactor's
|
||||
`${XDG_RUNTIME_DIR}/tractor/<name>@<pid>.sock` file
|
||||
accumulates on the filesystem (see issue #454 + the
|
||||
autouse `_track_orphaned_uds_per_test` fixture).
|
||||
|
||||
Two cleanup paths, in order:
|
||||
|
||||
1. **Explicit `bind_addrs`** — when the parent set the
|
||||
subactor's bind addrs at spawn time, unlink each
|
||||
UDS-flavored sockpath directly.
|
||||
2. **Self-assigned reconstruction** — when
|
||||
`bind_addrs` is empty (the common case: subactor
|
||||
picked its own random sock via
|
||||
`UDSAddress.get_random()`), reconstruct the path
|
||||
from `(subactor.aid.name, proc.pid)` using the
|
||||
same `<name>@<pid>.sock` convention. We can do this
|
||||
because the subactor uses its OWN `os.getpid()` at
|
||||
bind time, which equals `proc.pid` from the
|
||||
parent's view.
|
||||
|
||||
Idempotent: `FileNotFoundError` (graceful exit
|
||||
already-unlinked, or sock never bound under early-
|
||||
spawn cancel) is silenced; other `OSError`s log a
|
||||
warning but never raise. TCP / non-UDS bind addrs are
|
||||
skipped.
|
||||
|
||||
'''
|
||||
sockpaths: list[str] = []
|
||||
|
||||
# path 1: explicit bind_addrs set at spawn time
|
||||
for unwrapped in (bind_addrs or ()):
|
||||
try:
|
||||
addr = wrap_address(unwrapped)
|
||||
except Exception:
|
||||
log.exception(
|
||||
f'Failed to wrap addr for UDS post-kill cleanup '
|
||||
f'— skipping {unwrapped!r}\n'
|
||||
)
|
||||
continue
|
||||
if isinstance(addr, UDSAddress):
|
||||
sockpaths.append(str(addr.sockpath))
|
||||
|
||||
# path 2: reconstruct from subactor name + proc pid
|
||||
# for the random-self-assign case (bind_addrs=None)
|
||||
#
|
||||
# TODO authoritative tracking — see module docstring.
|
||||
if (
|
||||
not sockpaths
|
||||
and subactor is not None
|
||||
and proc.pid is not None
|
||||
):
|
||||
sockname: str = f'{subactor.aid.name}@{proc.pid}.sock'
|
||||
sockpath: str = str(
|
||||
UDSAddress.def_bindspace / sockname
|
||||
)
|
||||
sockpaths.append(sockpath)
|
||||
|
||||
for sockpath in sockpaths:
|
||||
try:
|
||||
os.unlink(sockpath)
|
||||
log.runtime(
|
||||
f'Unlinked orphaned UDS sock-file post-SIGKILL\n'
|
||||
f' |_{proc}\n'
|
||||
f' |_{sockpath}\n'
|
||||
)
|
||||
except FileNotFoundError:
|
||||
# raced — subactor cleaned up before SIGKILL,
|
||||
# OR sockfile never bound (early-spawn cancel),
|
||||
# OR transport wasn't UDS this run.
|
||||
pass
|
||||
except OSError as exc:
|
||||
log.warning(
|
||||
f'Failed to unlink subactor UDS sock-file '
|
||||
f'post-SIGKILL\n'
|
||||
f' |_{proc}\n'
|
||||
f' |_{sockpath}\n'
|
||||
f' |_{exc!r}\n'
|
||||
)
|
||||
|
|
@ -39,7 +39,10 @@ from tractor.runtime._state import (
|
|||
_runtime_vars,
|
||||
)
|
||||
from tractor.log import get_logger
|
||||
from tractor.discovery._addr import UnwrappedAddress
|
||||
from tractor.discovery._addr import (
|
||||
UnwrappedAddress,
|
||||
)
|
||||
from ._reap import unlink_uds_bind_addrs
|
||||
from tractor.runtime._portal import Portal
|
||||
from tractor.runtime._runtime import Actor
|
||||
from tractor.msg import types as msgtypes
|
||||
|
|
@ -223,6 +226,16 @@ async def hard_kill(
|
|||
# whilst also hacking on it XD
|
||||
# terminate_after: int = 99999,
|
||||
|
||||
*,
|
||||
# Subactor's bind addresses + subactor record, used
|
||||
# for post-SIGKILL UDS sockpath cleanup. Optional for
|
||||
# legacy callers; new call sites should pass at least
|
||||
# `subactor` (which lets us reconstruct the sock path
|
||||
# from `aid.name + proc.pid` when `bind_addrs` is
|
||||
# empty/self-assigned). See `._reap.unlink_uds_bind_addrs()`.
|
||||
bind_addrs: list[UnwrappedAddress] | None = None,
|
||||
subactor: Actor | None = None,
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
Un-gracefully terminate an OS level `trio.Process` after timeout.
|
||||
|
|
@ -310,6 +323,21 @@ async def hard_kill(
|
|||
)
|
||||
proc.kill()
|
||||
|
||||
# Post-mortem UDS sockpath cleanup. SIGKILL bypassed
|
||||
# the subactor's normal `os.unlink(addr.sockpath)` in
|
||||
# `_serve_ipc_eps`'s `finally:`; the parent has the
|
||||
# bind addrs (or can reconstruct from name + pid) so
|
||||
# we do it here. Runs UNCONDITIONALLY (graceful-exit
|
||||
# case is a no-op via `FileNotFoundError` skip in the
|
||||
# helper) so the cleanup also covers the "cancelled
|
||||
# during spawn" path where the subactor never reached
|
||||
# its IPC server finally block.
|
||||
unlink_uds_bind_addrs(
|
||||
proc,
|
||||
bind_addrs=bind_addrs,
|
||||
subactor=subactor,
|
||||
)
|
||||
|
||||
|
||||
async def soft_kill(
|
||||
proc: ProcessType,
|
||||
|
|
|
|||
|
|
@ -282,7 +282,23 @@ async def trio_proc(
|
|||
|
||||
if proc.poll() is None:
|
||||
log.cancel(f"Attempting to hard kill {proc}")
|
||||
await hard_kill(proc)
|
||||
await hard_kill(
|
||||
proc,
|
||||
# NOTE, pass through so post-SIGKILL we
|
||||
# can `os.unlink()` the subactor's
|
||||
# orphaned UDS sock-file(s) — the
|
||||
# subactor's own
|
||||
# `_serve_ipc_eps`-`finally:` cleanup
|
||||
# never runs under SIGKILL. `subactor`
|
||||
# lets the helper reconstruct the
|
||||
# sock path via `aid.name + proc.pid`
|
||||
# when `bind_addrs` is the common
|
||||
# self-assigned-random case
|
||||
# (bind_addrs=None at spawn). See
|
||||
# `_unlink_uds_bind_addrs()` in `_spawn`.
|
||||
bind_addrs=bind_addrs,
|
||||
subactor=subactor,
|
||||
)
|
||||
|
||||
log.debug(f"Joined {proc}")
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from contextlib import asynccontextmanager as acm
|
|||
from dataclasses import dataclass
|
||||
import inspect
|
||||
import platform
|
||||
import sys
|
||||
import traceback
|
||||
from typing import (
|
||||
Any,
|
||||
|
|
@ -810,6 +811,151 @@ def _run_asyncio_task(
|
|||
return chan
|
||||
|
||||
|
||||
def maybe_signal_aio_task(
|
||||
aio_task: asyncio.Task,
|
||||
exc: BaseException,
|
||||
*,
|
||||
cause: BaseException|None = None,
|
||||
pre_captured_fut: asyncio.Future|None = None,
|
||||
allow_cancel_fallback: bool = False,
|
||||
|
||||
) -> tuple[bool, str]:
|
||||
'''
|
||||
Best-effort delivery of `exc` to a still-running `aio_task`
|
||||
via its `_fut_waiter` (the `asyncio.Future` the task is
|
||||
currently `await`-ing on).
|
||||
|
||||
Returns `(delivered, report)` where `delivered=True` iff
|
||||
either,
|
||||
- `fut.set_exception(exc)` was successfully called on an
|
||||
un-`done()` `_fut_waiter`, OR
|
||||
- the cancel-fallback path fired (only when the caller
|
||||
opted-in via `allow_cancel_fallback=True`).
|
||||
|
||||
Why `_fut_waiter.set_exception(exc)` and NOT
|
||||
`aio_task.set_exception(exc)`:
|
||||
|
||||
On py3.13+ `asyncio.Task.set_exception()` ALWAYS raises
|
||||
`RuntimeError("Task does not support set_exception
|
||||
operation")` — so calling it as a relay mechanism is dead
|
||||
code. The `_fut_waiter` is a plain `asyncio.Future` and
|
||||
its `set_exception()` works on all Python versions; the
|
||||
task's `_wakeup` callback then propagates the exc into
|
||||
the coro on its next tick.
|
||||
|
||||
Why we PREFER NOT to call `aio_task.cancel()`:
|
||||
|
||||
`Task.cancel()` injects a `CancelledError` that races
|
||||
any in-flight exception already queued on `_fut_waiter`
|
||||
(e.g. via a prior `set_exception()` from a sibling
|
||||
teardown path). The race can mask BOTH the original
|
||||
trio-side error and any asyncio-side error the task was
|
||||
mid-raising. See the
|
||||
`test_trio_closes_early_and_channel_exits` hang TODO
|
||||
around the `translate_aio_errors` finally for the
|
||||
historical artifact.
|
||||
|
||||
However a caller may have NO OTHER way to terminate the
|
||||
task — when `_fut_waiter is None` AND the task is busy
|
||||
looping / runnable, neither `set_exception` nor a chan
|
||||
close can poke it. In that narrow case `cancel()` is the
|
||||
only available termination signal; opt-in via
|
||||
`allow_cancel_fallback=True`. The fallback NEVER runs
|
||||
when `_fut_waiter` carries an in-flight exc (the
|
||||
`fut.done()` branch); only when there's truly no
|
||||
`_fut_waiter` ref to poke.
|
||||
|
||||
Pre-checkpoint capture:
|
||||
|
||||
`asyncio.Task._wakeup` clears `_fut_waiter = None` as
|
||||
part of the wakeup sequence. If the caller crosses a
|
||||
trio checkpoint between fut-capture and this call,
|
||||
re-reading `aio_task._fut_waiter` will see `None` even
|
||||
though the exc is still in flight on the (now-`done()`)
|
||||
original fut. Pass `pre_captured_fut` to use the
|
||||
already-captured reference.
|
||||
|
||||
Causal chaining via `cause`:
|
||||
|
||||
Pass the underlying trio-side exc (the *reason* we're
|
||||
poking the aio side) via `cause` and the helper sets
|
||||
`exc.__cause__ = cause`. The chain travels with `exc`
|
||||
through `_fut_waiter.set_exception()` → `Task._wakeup`
|
||||
→ coro raise → `wait_on_coro_final_result`'s except →
|
||||
`signal_trio_when_done`'s `task.result()`-`raise
|
||||
aio_err`. The final traceback then renders as
|
||||
"<trio-side exc> -> (direct cause of) -> <relay exc>"
|
||||
instead of an opaque, root-cause-detached relay.
|
||||
|
||||
See the "cross-loop cause-chain matrix" comment in
|
||||
`translate_aio_errors()`'s final-raise block for how this
|
||||
`cause` interacts with every `raise X [from Y]` exit path
|
||||
(esp. the relay-echo guard which prevents a cause CYCLE).
|
||||
|
||||
'''
|
||||
if cause is not None and exc.__cause__ is None:
|
||||
exc.__cause__ = cause
|
||||
|
||||
if aio_task.done():
|
||||
return False, (
|
||||
f'aio-task already done; nothing to signal\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
|
||||
fut: asyncio.Future|None = (
|
||||
pre_captured_fut
|
||||
if pre_captured_fut is not None
|
||||
else aio_task._fut_waiter
|
||||
)
|
||||
|
||||
if fut and not fut.done():
|
||||
fut.set_exception(exc)
|
||||
return True, (
|
||||
f'signalled aio-task via `_fut_waiter.set_exception()`\n'
|
||||
f'exc: {exc!r}\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
|
||||
if fut and fut.done():
|
||||
# NEVER cancel here even when `allow_cancel_fallback=True`
|
||||
# — the in-flight exc on `fut` will terminate the task
|
||||
# on its next tick; injecting `CancelledError` on top
|
||||
# would race and mask the real exc.
|
||||
return False, (
|
||||
f'`_fut_waiter` already signalled with,\n'
|
||||
f' |_{fut.exception()!r}\n'
|
||||
f'aio-task will exit on next tick via the in-flight exc;\n'
|
||||
f'SKIPPING re-signal (would race in-flight delivery).\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
|
||||
# fut is None — task is runnable (sitting in asyncio's
|
||||
# ready queue), not parked on a future we can poke.
|
||||
if allow_cancel_fallback:
|
||||
cancel_msg: str = (
|
||||
f'\n'
|
||||
f'MANUALLY Cancelling `asyncio`-task: '
|
||||
f'{aio_task.get_name()}!\n\n'
|
||||
f'**THIS CAN SILENTLY SUPPRESS ERRORS FYI\n\n'
|
||||
)
|
||||
aio_task.cancel(msg=cancel_msg)
|
||||
return True, (
|
||||
f'aio-task has no `_fut_waiter`; FALLBACK cancel issued\n'
|
||||
f'(caller opted-in via `allow_cancel_fallback=True`).\n'
|
||||
f'{cancel_msg}'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
|
||||
return False, (
|
||||
f'aio-task has no `_fut_waiter`; cannot signal without\n'
|
||||
f'`aio_task.cancel()` which can mask errors.\n'
|
||||
f'LEAVING AS-IS (caller did NOT opt-in to cancel fallback);\n'
|
||||
f'task should exit via chan close / aio-loop teardown\n'
|
||||
f'already in flight.\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
|
||||
|
||||
@acm
|
||||
async def translate_aio_errors(
|
||||
chan: LinkedTaskChannel,
|
||||
|
|
@ -985,38 +1131,25 @@ async def translate_aio_errors(
|
|||
# if isinstance(chan._aio_err, AsyncioTaskExited):
|
||||
# await tractor.pause(shield=True)
|
||||
|
||||
# if aio side is still active cancel it due to the trio-side
|
||||
# error!
|
||||
# if aio side is still active relay the trio-side error
|
||||
# to it via `_fut_waiter.set_exception()`.
|
||||
# ?TODO, mk `AsyncioCancelled[typeof(trio_err)]` embed the
|
||||
# current exc?
|
||||
if (
|
||||
# not aio_task.cancelled()
|
||||
# and
|
||||
not aio_task.done() # TODO? only need this one?
|
||||
|
||||
# XXX LOL, so if it's not set it's an error !?
|
||||
# yet another good jerb by `ascyncio`..
|
||||
# and
|
||||
# not aio_task.exception()
|
||||
):
|
||||
aio_taskc = TrioCancelled(
|
||||
f'The `trio`-side task crashed!\n'
|
||||
f'{trio_err}'
|
||||
)
|
||||
# ??TODO? move this into the func that tries to use
|
||||
# `Task._fut_waiter: Future` instead??
|
||||
#
|
||||
# aio_task.set_exception(aio_taskc)
|
||||
# wait_on_aio_task = False
|
||||
try:
|
||||
aio_task.set_exception(aio_taskc)
|
||||
except (
|
||||
asyncio.InvalidStateError,
|
||||
RuntimeError,
|
||||
# ^XXX, uhh bc apparently we can't use `.set_exception()`
|
||||
# any more XD .. ??
|
||||
):
|
||||
wait_on_aio_task = False
|
||||
aio_taskc = TrioCancelled(
|
||||
f'The `trio`-side task crashed!\n'
|
||||
f'{trio_err}'
|
||||
)
|
||||
delivered, report = maybe_signal_aio_task(
|
||||
aio_task,
|
||||
aio_taskc,
|
||||
# so the relay carries a "<trio_err> -> caused ->
|
||||
# TrioCancelled" chain when it eventually re-raises
|
||||
# on the aio side.
|
||||
cause=trio_err,
|
||||
)
|
||||
if not delivered:
|
||||
wait_on_aio_task = False
|
||||
log.cancel(report)
|
||||
|
||||
finally:
|
||||
# record wtv `trio`-side error transpired
|
||||
|
|
@ -1099,60 +1232,54 @@ async def translate_aio_errors(
|
|||
if _py_313:
|
||||
chan._to_aio.shutdown()
|
||||
|
||||
# XXX CRITICAL ordering: capture `_fut_waiter`
|
||||
# BEFORE the checkpoint. `asyncio.Task._wakeup`
|
||||
# clears `_fut_waiter = None` as part of wakeup,
|
||||
# so re-reading after the checkpoint loses the
|
||||
# ref even though the exc is still in-flight on
|
||||
# the (now-`done()`) original fut. The helper
|
||||
# uses `pre_captured_fut` to recover that.
|
||||
pre_cp_fut: asyncio.Future|None = aio_task._fut_waiter
|
||||
|
||||
# pump this event-loop (well `Runner` but ya)
|
||||
#
|
||||
# TODO? is this actually needed?
|
||||
# -[ ] theory is this let's the aio side error on
|
||||
# next tick and then we sync task states from
|
||||
# here onward?
|
||||
# so the aio side can error on next tick and we
|
||||
# sync task states from here onward.
|
||||
await trio.lowlevel.checkpoint()
|
||||
|
||||
# TODO? factor the next 2 branches into a func like
|
||||
# `try_terminate_aio_task()` and use it for the taskc
|
||||
# case above as well?
|
||||
fut: asyncio.Future|None = aio_task._fut_waiter
|
||||
if (
|
||||
fut
|
||||
and
|
||||
not fut.done()
|
||||
):
|
||||
# await tractor.pause()
|
||||
if graceful_trio_exit:
|
||||
fut.set_exception(
|
||||
TrioTaskExited(
|
||||
f'the `trio.Task` gracefully exited but '
|
||||
f'its `asyncio` peer is not done?\n'
|
||||
f')>\n'
|
||||
f' |_{trio_task}\n'
|
||||
f'\n'
|
||||
f'>>\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
)
|
||||
|
||||
# TODO? should this need to exist given the equiv
|
||||
# `TrioCancelled` equivalent in the be handler
|
||||
# above??
|
||||
else:
|
||||
fut.set_exception(
|
||||
TrioTaskExited(
|
||||
f'The `trio`-side task crashed!\n'
|
||||
f'{trio_err}'
|
||||
)
|
||||
)
|
||||
else:
|
||||
aio_taskc_warn: str = (
|
||||
if graceful_trio_exit:
|
||||
relay_exc = TrioTaskExited(
|
||||
f'the `trio.Task` gracefully exited but '
|
||||
f'its `asyncio` peer is not done?\n'
|
||||
f')>\n'
|
||||
f' |_{trio_task}\n'
|
||||
f'\n'
|
||||
f'MANUALLY Cancelling `asyncio`-task: {aio_task.get_name()}!\n\n'
|
||||
f'**THIS CAN SILENTLY SUPPRESS ERRORS FYI\n\n'
|
||||
f'>>\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
# await tractor.pause()
|
||||
report += aio_taskc_warn
|
||||
# TODO XXX, figure out the case where calling this makes the
|
||||
# `test_infected_asyncio.py::test_trio_closes_early_and_channel_exits`
|
||||
# hang and then don't call it in that case!
|
||||
#
|
||||
aio_task.cancel(msg=aio_taskc_warn)
|
||||
else:
|
||||
relay_exc = TrioTaskExited(
|
||||
f'The `trio`-side task crashed!\n'
|
||||
f'{trio_err}'
|
||||
)
|
||||
|
||||
delivered, signal_report = maybe_signal_aio_task(
|
||||
aio_task,
|
||||
relay_exc,
|
||||
pre_captured_fut=pre_cp_fut,
|
||||
# XXX historically this branch called
|
||||
# `aio_task.cancel()` when `_fut_waiter`
|
||||
# was None — required to actually terminate
|
||||
# aio tasks that aren't parked on a poke-able
|
||||
# future (e.g. the `aio_echo_server` loop in
|
||||
# `test_echoserver_detailed_mechanics`). Opt
|
||||
# into the fallback so we don't regress.
|
||||
allow_cancel_fallback=True,
|
||||
# carry the trio-side exc (if any) as the
|
||||
# cause so the aio-side relay shows the
|
||||
# real root-cause chain when re-raised.
|
||||
cause=trio_err,
|
||||
)
|
||||
report += signal_report
|
||||
|
||||
log.warning(report)
|
||||
|
||||
|
|
@ -1161,10 +1288,11 @@ async def translate_aio_errors(
|
|||
# `channel._aio_err/._trio_to_raise`) BEFORE calling
|
||||
# `maybe_raise_aio_side_err()` below!
|
||||
#
|
||||
# XXX WARNING NOTE
|
||||
# the `task.set_exception(aio_taskc)` call above MUST NOT
|
||||
# EXCEPT or this WILL HANG!! SO, if you get a hang maybe step
|
||||
# through and figure out why it erroed out up there!
|
||||
# NOTE, `wait_on_aio_task` may have been flipped to `False`
|
||||
# by `maybe_signal_aio_task()` above when delivery
|
||||
# failed (e.g. `_fut_waiter is None`) — in that case we
|
||||
# skip the wait since the aio task won't process our
|
||||
# relay exc and `_aio_task_complete` may never set.
|
||||
#
|
||||
if wait_on_aio_task:
|
||||
await chan._aio_task_complete.wait()
|
||||
|
|
@ -1181,6 +1309,47 @@ async def translate_aio_errors(
|
|||
- `run_task()`
|
||||
|
||||
'''
|
||||
# ===== cross-loop cause-chain matrix =====
|
||||
# How `(trio_err, aio_err, trio_to_raise)` resolve into ONE
|
||||
# terminal `raise X [from Y]` (or an early `return`).
|
||||
#
|
||||
# legend (the possible `X` / `Y` operands):
|
||||
# - trio_err : `chan._trio_err`, the trio-side exc.
|
||||
# - aio_err : `chan._aio_err`, the aio-side exc.
|
||||
# - trio_to_raise : `chan._trio_to_raise`, a tractor-chosen
|
||||
# relay exc (`AsyncioCancelled`/`AsyncioTaskExited`).
|
||||
# - raise_from : `trio_err if (aio_err is trio_to_raise)
|
||||
# else aio_err` (the chosen `__cause__`).
|
||||
# - relay-echo : an `aio_err` that is one of OUR OWN
|
||||
# `TrioTaskExited|TrioCancelled` signals,
|
||||
# synth'd + delivered to the aio-side by
|
||||
# `maybe_signal_aio_task()`; its `__cause__`
|
||||
# is ALREADY `trio_err`.
|
||||
# - "(bare)" : raised with NO explicit `from` clause.
|
||||
#
|
||||
# this block (final-raise in `translate_aio_errors`):
|
||||
# condition => raises from
|
||||
# ----------------------------------- ------------- -----------
|
||||
# not suppress_graceful_exits => trio_to_raise raise_from
|
||||
# AsyncioTaskExited + trio Cancelled/None => return (aio-exit ignored)
|
||||
# AsyncioTaskExited + trio EoC => trio_err (bare)
|
||||
# AsyncioCancelled + trio Cancelled => return (co-cancel ignored)
|
||||
# trio_to_raise match catch-all => trio_to_raise raise_from
|
||||
# aio_err is relay-echo ◄── the GUARD => trio_err (bare)
|
||||
# aio_err independent (real aio fail) => trio_err aio_err
|
||||
# aio_err independent, no trio_err => aio_err (bare)
|
||||
# only trio_err => trio_err (bare)
|
||||
#
|
||||
# sibling block (`signal_trio_when_done()`, the aio done-cb):
|
||||
# AsyncioTaskExited relay-out => trio_to_raise aio_err
|
||||
# plain aio_err re-raise => aio_err (__cause__ preset)
|
||||
#
|
||||
# INVARIANT: a relay-echo must NEVER become `trio_err.__cause__`
|
||||
# (it's ALREADY caused-BY `trio_err`) → doing so would CYCLE
|
||||
# (`trio_err ◄─► relay`). So the guard raises the root
|
||||
# `trio_err` bare; the relay still keeps its own correct
|
||||
# "relay ◄ trio_err" chain for any aio-side inspection.
|
||||
# ===== / cross-loop cause-chain matrix =====
|
||||
aio_err: BaseException|None = chan._aio_err
|
||||
trio_to_raise: (
|
||||
AsyncioCancelled|
|
||||
|
|
@ -1237,6 +1406,32 @@ async def translate_aio_errors(
|
|||
and
|
||||
type(aio_err) is not AsyncioCancelled
|
||||
):
|
||||
# XXX, if `aio_err` is one of OUR OWN relay-signals
|
||||
# (`TrioTaskExited`/`TrioCancelled`) that we delivered
|
||||
# to the aio-side via `maybe_signal_aio_task()`, AND
|
||||
# its `__cause__` already points back at `trio_err`,
|
||||
# then it's just a derivative ECHO of the trio-side
|
||||
# error, NOT an independent asyncio failure.
|
||||
#
|
||||
# Raising `trio_err from aio_err` here would invert
|
||||
# (and cyclically tangle) the cause chain since the
|
||||
# relay was itself caused-by `trio_err`:
|
||||
#
|
||||
# trio_err.__cause__ = aio_err (from `raise .. from`)
|
||||
# aio_err.__cause__ = trio_err (set in `maybe_signal_aio_task`)
|
||||
#
|
||||
# So raise the REAL root `trio_err` alone; the relay's
|
||||
# own `__cause__` chain still correctly reads
|
||||
# "TrioTaskExited <- trio_err" for aio-side inspection.
|
||||
if (
|
||||
trio_err is not None
|
||||
and
|
||||
isinstance(aio_err, (TrioTaskExited, TrioCancelled))
|
||||
and
|
||||
aio_err.__cause__ is trio_err
|
||||
):
|
||||
raise trio_err
|
||||
|
||||
# always raise from any captured asyncio error
|
||||
if trio_err:
|
||||
raise trio_err from aio_err
|
||||
|
|
@ -1353,19 +1548,22 @@ async def open_channel_from(
|
|||
# a `Return`-msg for IPC ctxs)
|
||||
aio_task: asyncio.Task = chan._aio_task
|
||||
if not aio_task.done():
|
||||
fut: asyncio.Future|None = aio_task._fut_waiter
|
||||
if fut:
|
||||
fut.set_exception(
|
||||
TrioTaskExited(
|
||||
f'but the child `asyncio` task is still running?\n'
|
||||
f'>>\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
)
|
||||
)
|
||||
else:
|
||||
# XXX SHOULD NEVER HAPPEN!
|
||||
log.error("SHOULD NEVER GET HERE !?!?")
|
||||
await tractor.pause(shield=True)
|
||||
# capture the in-flight trio-side exc (if any)
|
||||
# so the relay's `__cause__` chain shows the
|
||||
# real root cause when the aio task re-raises.
|
||||
# `sys.exc_info()[1]` is non-`None` only when
|
||||
# the `try` body raised (graceful exit -> None).
|
||||
trio_exc: BaseException|None = sys.exc_info()[1]
|
||||
_, report = maybe_signal_aio_task(
|
||||
aio_task,
|
||||
TrioTaskExited(
|
||||
f'but the child `asyncio` task is still running?\n'
|
||||
f'>>\n'
|
||||
f' |_{aio_task!r}\n'
|
||||
),
|
||||
cause=trio_exc,
|
||||
)
|
||||
log.cancel(report)
|
||||
else:
|
||||
chan._to_trio.close()
|
||||
|
||||
|
|
@ -1602,6 +1800,7 @@ def run_as_asyncio_guest(
|
|||
fute_err: BaseException|None = None
|
||||
try:
|
||||
out: Outcome = await asyncio.shield(trio_done_fute)
|
||||
# out: Outcome = await trio_done_fute
|
||||
# ^TODO still don't really understand why the `.shield()`
|
||||
# is required ... ??
|
||||
# https://docs.python.org/3/library/asyncio-task.html#asyncio.shield
|
||||
|
|
|
|||
|
|
@ -36,4 +36,8 @@ from ._beg import (
|
|||
)
|
||||
from ._taskc import (
|
||||
maybe_raise_from_masking_exc as maybe_raise_from_masking_exc,
|
||||
start_or_cancel as start_or_cancel,
|
||||
)
|
||||
from ._subproc import (
|
||||
supervise_run_process as supervise_run_process,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,296 @@
|
|||
# tractor: distributed structured concurrency.
|
||||
# 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/>.
|
||||
|
||||
'''
|
||||
SC-friendly `trio.run_process()` supervision: a `tn.start()`
|
||||
style wrapper which surfaces rc!=0 errors deterministically and
|
||||
(optionally) live-relays the child's std-streams to the `tractor`
|
||||
log.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
from functools import partial
|
||||
import subprocess
|
||||
import textwrap
|
||||
from typing import (
|
||||
Callable,
|
||||
)
|
||||
|
||||
import trio
|
||||
|
||||
from ..log import get_logger
|
||||
|
||||
log = get_logger()
|
||||
|
||||
|
||||
# sentinel so `supervise_run_process(stdout=...)` can tell
|
||||
# "caller passed nothing" (-> tty-safe `DEVNULL` default) from
|
||||
# an explicit `stdout=None` (inherit) override.
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
def _add_stderr_note(
|
||||
cpe: subprocess.CalledProcessError,
|
||||
stderr_bytes: bytes,
|
||||
) -> None:
|
||||
'''
|
||||
Attach an indented `|_.stderr:` note to a
|
||||
`CalledProcessError` for legible rc!=0 reporting at
|
||||
teardown.
|
||||
|
||||
'''
|
||||
stderr_str: str = stderr_bytes.decode(errors='replace')
|
||||
cpe.add_note(
|
||||
f'|_.stderr:\n'
|
||||
f'{textwrap.indent(stderr_str, prefix=" "*3)}'
|
||||
)
|
||||
|
||||
|
||||
async def _relay_stream_lines(
|
||||
stream: trio.abc.ReceiveStream,
|
||||
*,
|
||||
emit: Callable[[str], None]|None = None,
|
||||
tag: str = '',
|
||||
accum: bytearray|None = None,
|
||||
) -> None:
|
||||
'''
|
||||
Concurrently drain a child subproc's `stdout`/`stderr`
|
||||
PIPE; relay each COMPLETE line to `emit` (a bound
|
||||
`log.<level>` method) prefixed with `tag` (e.g.
|
||||
`f'{label}:out'`) and/or append raw bytes to `accum`.
|
||||
|
||||
This reader is MANDATORY whenever a bare
|
||||
`stdout=`/`stderr=PIPE` is used WITHOUT `trio`'s
|
||||
`capture_*` (which would spawn trio's own internal drain
|
||||
task): nothing else drains the OS pipe, so once its kernel
|
||||
buffer (~64KiB) fills the child blocks on `write()` ->
|
||||
deadlock.
|
||||
|
||||
Modes (combine freely):
|
||||
- `emit`-only: live per-line relay (e.g. `relay_stdout`).
|
||||
- `accum`-only: silent drain + capture (e.g. stderr kept
|
||||
for a `CalledProcessError` note WITHOUT relaying it).
|
||||
- both: relay AND capture (e.g. `relay_stderr` with `check=True`).
|
||||
|
||||
'''
|
||||
# NOTE, mirrors `trio._subprocess`'s internal
|
||||
# `async with stream: async for ...` drain idiom — except
|
||||
# here we EMIT per-line (and/or accumulate) instead of
|
||||
# only accumulating.
|
||||
residual: bytes = b''
|
||||
async with stream: # aclose at EOF/cancel
|
||||
async for chunk in stream: # ends at child-exit EOF
|
||||
if accum is not None:
|
||||
accum += chunk
|
||||
if emit is None:
|
||||
continue # drain(+accum)-only
|
||||
buf: bytes = residual + chunk
|
||||
*lines, residual = buf.split(b'\n')
|
||||
for raw in lines:
|
||||
line: str = raw.decode(
|
||||
errors='replace',
|
||||
).rstrip('\r')
|
||||
emit(f'[{tag}] {line}')
|
||||
|
||||
# flush any trailing partial (un-newline-term'd) line @ EOF
|
||||
if (
|
||||
emit is not None
|
||||
and
|
||||
residual
|
||||
):
|
||||
line: str = residual.decode(
|
||||
errors='replace',
|
||||
).rstrip('\r')
|
||||
emit(f'[{tag}] {line}')
|
||||
|
||||
|
||||
async def supervise_run_process(
|
||||
cmd: list[str]|str,
|
||||
*,
|
||||
check: bool = True,
|
||||
label: str|None = None,
|
||||
|
||||
# per-line `log.*` relay of the child's std-streams
|
||||
# (tty-safe, capture-safe, STREAMED — not
|
||||
# buffered-until-exit, so it suits long-lived daemons).
|
||||
relay_stdout: bool = False,
|
||||
relay_stderr: bool = False,
|
||||
|
||||
# default `io` (our custom level, value 21): the relay
|
||||
# exists to make windowless-spawn output VISIBLE, and
|
||||
# `IO`(21) sorts just ABOVE `INFO`(20) so it shows at the
|
||||
# usual `info`/`devx` console levels (a `runtime`(15) relay
|
||||
# would be silently filtered) while staying distinctly
|
||||
# labelled + separately filterable.
|
||||
relay_level: str = 'io',
|
||||
|
||||
# non-relay `stdout` override; defaults (via `_UNSET`) to
|
||||
# `DEVNULL` so we NEVER inherit (+ thus can't clobber) the
|
||||
# parent controlling-tty.
|
||||
stdout: int = _UNSET,
|
||||
|
||||
task_status: trio.TaskStatus[
|
||||
trio.Process
|
||||
] = trio.TASK_STATUS_IGNORED,
|
||||
|
||||
# any other `trio.run_process()` kwarg (env, shell, cwd,
|
||||
# start_new_session, executable, ...) forwarded verbatim;
|
||||
# our MANAGED keys (stdin/stdout/stderr/check) are set
|
||||
# below and WIN on conflict.
|
||||
**run_process_kwargs,
|
||||
) -> None:
|
||||
'''
|
||||
A `trio.Nursery.start()`-style `trio.run_process()`
|
||||
wrapper which,
|
||||
|
||||
- surfaces a rc!=0 `subprocess.CalledProcessError`
|
||||
DETERMINISTICALLY: we pass `check=False` to `trio` and
|
||||
do our OWN post-drain rc-check, (re)building + raising a
|
||||
BARE CPE (with a `.stderr` note) from this coro's body
|
||||
AFTER the child exits — so there's no nursery-eg-wrapped
|
||||
CPE to catch/`collapse_eg`, and the relay reader is never
|
||||
race-cancelled mid-drain.
|
||||
|
||||
- ALWAYS isolates the parent controlling-tty
|
||||
(`stdin=DEVNULL`, and `stdout=DEVNULL` unless
|
||||
relayed/overridden) so a spawned program can't emit
|
||||
terminal control-seqs onto the launching tty (which
|
||||
would clobber its scrollback).
|
||||
|
||||
- optionally live-relays `stdout`/`stderr` per-line to
|
||||
`log.<relay_level>` via concurrent reader tasks (see
|
||||
`_relay_stream_lines`).
|
||||
|
||||
Delivers the live `trio.Process` via
|
||||
`task_status.started()` then SUPERVISES it (the
|
||||
`run_process` bg task + any relay readers) to completion
|
||||
in this coro — i.e. the parent `tn.start()` returns
|
||||
immediately/non-blocking.
|
||||
|
||||
NOTE: any crash-handling / `repl_fixture` layer is
|
||||
intentionally NOT baked in here — compose it ON TOP at the
|
||||
call-site, e.g.
|
||||
|
||||
async with maybe_open_crash_handler():
|
||||
await tn.start(
|
||||
partial(supervise_run_process, cmd, ...),
|
||||
)
|
||||
|
||||
'''
|
||||
emit: Callable[[str], None] = getattr(log, relay_level)
|
||||
tag: str = (
|
||||
label
|
||||
or
|
||||
(cmd if isinstance(cmd, str) else ' '.join(cmd))
|
||||
)
|
||||
|
||||
# forward any extra `trio.run_process` kwargs verbatim;
|
||||
# MANAGED keys below override on conflict.
|
||||
rp_kwargs: dict = dict(run_process_kwargs)
|
||||
|
||||
# XXX ALWAYS isolate the controlling-tty's stdin.
|
||||
rp_kwargs['stdin'] = subprocess.DEVNULL
|
||||
|
||||
# stdout: relay -> our own PIPE (drained by the reader
|
||||
# below); else an explicit override; else tty-safe
|
||||
# `DEVNULL`.
|
||||
if relay_stdout:
|
||||
rp_kwargs['stdout'] = subprocess.PIPE
|
||||
elif stdout is not _UNSET:
|
||||
rp_kwargs['stdout'] = stdout
|
||||
else:
|
||||
rp_kwargs['stdout'] = subprocess.DEVNULL
|
||||
|
||||
# stderr: PIPE (+ our reader) when we either RELAY it OR
|
||||
# need it captured for a rc!=0 CPE note; else tty-safe
|
||||
# `DEVNULL`. We accumulate ONLY when `check` (the note is
|
||||
# the only consumer).
|
||||
#
|
||||
# XXX we ALWAYS pass `check=False` to `trio` and do our
|
||||
# OWN deterministic post-drain rc-check (below) so `trio`
|
||||
# never raises a nursery-eg-wrapped CPE — no `collapse_eg`
|
||||
# workaround, no reader race-cancel.
|
||||
want_stderr_pipe: bool = relay_stderr or check
|
||||
stderr_accum: bytearray|None = bytearray() if check else None
|
||||
rp_kwargs['check'] = False
|
||||
rp_kwargs['stderr'] = (
|
||||
subprocess.PIPE if want_stderr_pipe
|
||||
else subprocess.DEVNULL
|
||||
)
|
||||
|
||||
async with trio.open_nursery() as own_tn:
|
||||
trio_proc: trio.Process = await own_tn.start(
|
||||
partial(
|
||||
trio.run_process,
|
||||
cmd,
|
||||
**rp_kwargs,
|
||||
)
|
||||
)
|
||||
|
||||
# spin up the concurrent pipe-drain relay reader(s) —
|
||||
# see `_relay_stream_lines` for why these are mandatory
|
||||
# (not cosmetic) when piping without `capture_*`.
|
||||
if relay_stdout:
|
||||
own_tn.start_soon(
|
||||
partial(
|
||||
_relay_stream_lines,
|
||||
trio_proc.stdout,
|
||||
emit=emit,
|
||||
tag=f'{tag}:out',
|
||||
)
|
||||
)
|
||||
if want_stderr_pipe:
|
||||
own_tn.start_soon(
|
||||
partial(
|
||||
_relay_stream_lines,
|
||||
trio_proc.stderr,
|
||||
# relay live only if asked; else silent
|
||||
# drain+capture for the CPE note.
|
||||
emit=emit if relay_stderr else None,
|
||||
tag=f'{tag}:err',
|
||||
accum=stderr_accum,
|
||||
)
|
||||
)
|
||||
|
||||
# hand the live proc up to the parent WITHOUT blocking
|
||||
# on the bg supervise/relay tasks (keeps non-blocking
|
||||
# `tn.start()` semantics).
|
||||
task_status.started(trio_proc)
|
||||
|
||||
# ===== deterministic post-drain rc-check (BOTH paths) =====
|
||||
# `own_tn` only unwinds once `run_process` AND the relay
|
||||
# reader(s) have hit EOF + FULLY drained — so `stderr_accum`
|
||||
# is COMPLETE here (no race vs an early CPE-cancel). Rebuild
|
||||
# + raise a BARE `CalledProcessError` (the parent `tn` will
|
||||
# eg-wrap it like any task-raise; callers `collapse_eg()` if
|
||||
# they want it bare).
|
||||
if (
|
||||
check
|
||||
and
|
||||
trio_proc.returncode
|
||||
):
|
||||
stderr_bytes: bytes = (
|
||||
bytes(stderr_accum)
|
||||
if stderr_accum is not None
|
||||
else b''
|
||||
)
|
||||
cpe = subprocess.CalledProcessError(
|
||||
returncode=trio_proc.returncode,
|
||||
cmd=trio_proc.args,
|
||||
stderr=stderr_bytes,
|
||||
)
|
||||
_add_stderr_note(cpe, stderr_bytes)
|
||||
raise cpe
|
||||
|
|
@ -27,6 +27,9 @@ from types import (
|
|||
TracebackType,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
Awaitable,
|
||||
Callable,
|
||||
Type,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
|
@ -295,3 +298,53 @@ async def maybe_raise_from_masking_exc(
|
|||
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
async def start_or_cancel(
|
||||
nursery: trio.Nursery,
|
||||
async_fn: Callable[..., Awaitable[Any]],
|
||||
*args,
|
||||
name: object = None,
|
||||
|
||||
) -> Any:
|
||||
'''
|
||||
Like `trio.Nursery.start()` but DON'T mask an out-of-band
|
||||
cancellation as a (lossy) startup failure.
|
||||
|
||||
`trio.Nursery.start()` raises a generic
|
||||
`RuntimeError("child exited without calling
|
||||
task_status.started()")` whenever the started task exits
|
||||
BEFORE calling `task_status.started()` — INCLUDING the very
|
||||
common case where the child was cancelled out-of-band by an
|
||||
*ancestor* cancel-scope erroring/cancelling. In that case the
|
||||
original `trio.Cancelled` is swallowed and the caller is left
|
||||
with an opaque, root-cause-detached `RuntimeError`.
|
||||
|
||||
This wrapper re-surfaces any ambient (effective, hence
|
||||
ancestor-inclusive) cancellation via
|
||||
`trio.lowlevel.checkpoint_if_cancelled()` so the real
|
||||
`trio.Cancelled` (carrying trio's auto-generated reason which
|
||||
points at the true root exc) propagates instead. Only when we
|
||||
are NOT under cancellation is the "didn't call `.started()`"
|
||||
`RuntimeError` a genuine startup-protocol bug worth surfacing,
|
||||
so it's re-raised as-is in that case.
|
||||
|
||||
'''
|
||||
try:
|
||||
return await nursery.start(
|
||||
async_fn,
|
||||
*args,
|
||||
name=name,
|
||||
)
|
||||
except RuntimeError as rte:
|
||||
if (
|
||||
rte.args
|
||||
and
|
||||
'started' in rte.args[0]
|
||||
):
|
||||
# re-raises the in-flight `trio.Cancelled` IFF we're
|
||||
# under effective cancellation; else a cheap no-op and
|
||||
# we fall through to re-raise the genuine startup RTE.
|
||||
await trio.lowlevel.checkpoint_if_cancelled()
|
||||
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
# `tractor.trionics.patches`
|
||||
|
||||
Defensive monkey-patches for bugs in `trio` itself.
|
||||
|
||||
## What goes here
|
||||
|
||||
- Bugs in upstream `trio` that we've encountered while
|
||||
running `tractor` and need to work around until
|
||||
upstream releases a fix.
|
||||
- Each patch fixes EXACTLY one trio internal — no
|
||||
multi-bug omnibus patches.
|
||||
|
||||
## What does NOT go here
|
||||
|
||||
- Bugs in `tractor`'s own code (those get fixed
|
||||
in-tree, in the offending tractor module).
|
||||
- Bugs in `asyncio`, `pytest`, the stdlib, etc. (file
|
||||
separate `tractor.<lib>.patches` subpkgs as
|
||||
needed).
|
||||
- Workarounds for behavior we *disagree* with but that
|
||||
isn't a bug per se. If trio's API does what it says
|
||||
on the tin, we don't override it here.
|
||||
|
||||
## Per-patch contract
|
||||
|
||||
Every `_<topic>.py` module in this directory MUST
|
||||
expose:
|
||||
|
||||
- **`apply() -> bool`** — apply the patch. Idempotent
|
||||
(safe to call multiple times). Version-gated — must
|
||||
consult `is_needed()` and skip when False. Returns
|
||||
`True` if patched this call, `False` if skipped.
|
||||
|
||||
- **`is_needed() -> bool`** — does upstream still need
|
||||
patching? Today most patches return `True`
|
||||
unconditionally, but as upstream releases land each
|
||||
should gate on `Version(trio.__version__) <
|
||||
Version('X.Y.Z')`. When the gated version is
|
||||
released, the patch can be DELETED entirely.
|
||||
|
||||
- **`repro() -> None`** — minimal demonstration of the
|
||||
bug. Used by the regression test suite to assert (a)
|
||||
the upstream bug still exists, (b) our patch fixes
|
||||
it. Should be tight enough that calling it post-
|
||||
`apply()` returns cleanly within a few hundred
|
||||
milliseconds — tests wrap it with a wall-clock cap.
|
||||
|
||||
Each module's docstring MUST contain:
|
||||
|
||||
- **Problem**: what trio does wrong + the trigger
|
||||
conditions (e.g. "fork-spawn backend, peer-closed
|
||||
socketpair, etc.")
|
||||
- **Fix**: the one-line (ideally) patch
|
||||
- **Repro**: the standalone snippet `repro()`
|
||||
implements
|
||||
- **Upstream**: link to filed issue/PR (or
|
||||
`TODO: file`)
|
||||
- **REMOVE WHEN**: `trio>=X.Y.Z` ships the upstream
|
||||
fix
|
||||
|
||||
## Adding a patch
|
||||
|
||||
1. Create `_<topic>.py` with the `apply` /
|
||||
`is_needed` / `repro` API.
|
||||
2. Register it in `__init__.py::_PATCHES`.
|
||||
3. Add a regression test in
|
||||
`tests/trionics/test_patches.py` that uses
|
||||
`repro()` to assert pre/post-patch behavior with a
|
||||
wall-clock cap.
|
||||
4. File the upstream issue/PR. Add the link to your
|
||||
module's `Upstream:` and `# REMOVE WHEN:` lines.
|
||||
|
||||
## Removing a patch (when upstream releases the fix)
|
||||
|
||||
1. Confirm the upstream-fixed `trio` version is the
|
||||
minimum we depend on, OR keep the version-gate in
|
||||
`is_needed()` if we still support older trio.
|
||||
2. If we've fully bumped past the broken versions:
|
||||
- Delete `_<topic>.py`
|
||||
- Remove the entry from `__init__.py::_PATCHES`
|
||||
- Delete the corresponding test in
|
||||
`tests/trionics/test_patches.py`
|
||||
- Bump the conc-anal doc with a "FIXED" header
|
||||
|
||||
## Calling
|
||||
|
||||
```python
|
||||
from tractor.trionics.patches import apply_all
|
||||
apply_all()
|
||||
```
|
||||
|
||||
Currently invoked from `tractor._child._actor_child_main`
|
||||
before `_trio_main` so every spawned subactor gets
|
||||
patched. The root actor's entry could opt in too if a
|
||||
patch turns out to bite the root (none do today).
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
# 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/>.
|
||||
|
||||
'''
|
||||
Defensive monkey-patches for `trio` internals.
|
||||
|
||||
Every patch in this package fixes a bug in `trio` itself
|
||||
that we've encountered while running `tractor` — usually
|
||||
a fork-survival edge case that upstream `trio` hasn't
|
||||
filed/fixed yet. Each patch is:
|
||||
|
||||
- **idempotent** — safe to call multiple times
|
||||
- **version-gated** — checks `trio.__version__` and skips
|
||||
itself if upstream has shipped the fix
|
||||
- **scoped** — only modifies the specific trio internal
|
||||
it's targeting; no broad side effects
|
||||
- **removable** — every patch carries a `# REMOVE WHEN:`
|
||||
marker in its docstring pointing at the upstream PR
|
||||
whose release allows us to drop it
|
||||
|
||||
Add a new patch by:
|
||||
|
||||
1. Create `tractor/trionics/patches/_<topic>.py` exposing
|
||||
the `apply()` / `is_needed()` / `repro()` API
|
||||
contract.
|
||||
2. Import it in this `__init__.py` and add an entry to
|
||||
`_PATCHES`.
|
||||
3. Document upstream-fix-tracking in the module
|
||||
docstring's `# REMOVE WHEN:` line.
|
||||
4. Add a regression test in
|
||||
`tests/trionics/test_patches.py` that uses the
|
||||
patch's `repro()` to assert the bug exists + the
|
||||
patch fixes it.
|
||||
|
||||
Calling `apply_all()` from a tractor entry point (e.g.
|
||||
`tractor._child._actor_child_main`) applies every
|
||||
registered patch + returns `{patch_name: applied?}` so
|
||||
callers can log/assert as needed.
|
||||
|
||||
'''
|
||||
from typing import Callable
|
||||
|
||||
from . import _wakeup_socketpair
|
||||
|
||||
|
||||
_PATCHES: list[tuple[str, Callable[[], bool]]] = [
|
||||
(
|
||||
'trio_wakeup_socketpair_drain_eof',
|
||||
_wakeup_socketpair.apply,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def apply_all() -> dict[str, bool]:
|
||||
'''
|
||||
Apply every registered patch. Idempotent — calling
|
||||
twice is fine, second call's dict will be all
|
||||
`False`.
|
||||
|
||||
Returns `{patch_name: applied?}`:
|
||||
|
||||
- `True` — patch was applied THIS call (inaugural
|
||||
apply, or first-call-since-process-start).
|
||||
- `False` — skipped (already applied OR upstream fix
|
||||
detected via `is_needed() == False`).
|
||||
|
||||
'''
|
||||
results: dict[str, bool] = {}
|
||||
for name, applier in _PATCHES:
|
||||
results[name] = applier()
|
||||
return results
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
# 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/>.
|
||||
|
||||
'''
|
||||
Patch `trio._core._wakeup_socketpair.WakeupSocketpair.drain()`
|
||||
to break on peer-closed EOF.
|
||||
|
||||
Problem
|
||||
-------
|
||||
`drain()` loops on `self.wakeup_sock.recv(2**16)` and
|
||||
exits ONLY on `BlockingIOError` (buffer-empty on a
|
||||
non-blocking socket), NEVER on `recv() == b''`
|
||||
(peer-closed FIN). When the socketpair's write-end
|
||||
has been closed, `recv` returns 0 bytes each call →
|
||||
infinite C-level tight loop → 100% CPU, no Python
|
||||
checkpoints, no signal delivery, no progress.
|
||||
|
||||
Most reliably triggered under fork-spawn backends —
|
||||
`os.fork()` + `_close_inherited_fds()` can leave a
|
||||
`WakeupSocketpair` instance whose `write_sock` was
|
||||
closed in the child (or whose peer-end is held by a
|
||||
process that has since exited).
|
||||
|
||||
Repro
|
||||
-----
|
||||
```python
|
||||
from trio._core._wakeup_socketpair import WakeupSocketpair
|
||||
ws = WakeupSocketpair()
|
||||
ws.write_sock.close()
|
||||
ws.drain() # spins forever pre-patch
|
||||
```
|
||||
|
||||
Fix
|
||||
---
|
||||
One line: break the drain loop on `b''` EOF
|
||||
in addition to the existing `BlockingIOError` exit.
|
||||
|
||||
```python
|
||||
def _safe_drain(self) -> None:
|
||||
try:
|
||||
while True:
|
||||
data = self.wakeup_sock.recv(2**16)
|
||||
if not data: # ← peer-closed; nothing more to drain
|
||||
return
|
||||
except BlockingIOError:
|
||||
pass
|
||||
```
|
||||
|
||||
Upstream
|
||||
--------
|
||||
TODO: file at `python-trio/trio` — the standalone
|
||||
`repro()` below + this docstring is the issue body's
|
||||
evidence section.
|
||||
|
||||
REMOVE WHEN: trio>=`<TBD>` ships the EOF-break in
|
||||
`_wakeup_socketpair.WakeupSocketpair.drain()`.
|
||||
|
||||
See also
|
||||
--------
|
||||
- `ai/conc-anal/trio_wakeup_socketpair_busy_loop_under_fork_issue.md`
|
||||
- `ai/conc-anal/infected_asyncio_under_main_thread_forkserver_hang_issue.md`
|
||||
— sibling-bug analysis fixed by the same patch.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
# Module-local sentinel — set True by `apply()` after the
|
||||
# first successful patch. Idempotency guard.
|
||||
_APPLIED: bool = False
|
||||
|
||||
|
||||
def is_needed() -> bool:
|
||||
'''
|
||||
True iff upstream `trio` is the broken version that
|
||||
needs our patch.
|
||||
|
||||
Today: always True since no released `trio` has the
|
||||
fix. When upstream lands it, gate on:
|
||||
|
||||
```python
|
||||
from packaging.version import Version
|
||||
import trio
|
||||
return Version(trio.__version__) < Version('<TBD>')
|
||||
```
|
||||
|
||||
'''
|
||||
# TODO version-gate once upstream lands the fix.
|
||||
return True
|
||||
|
||||
|
||||
def repro() -> None:
|
||||
'''
|
||||
Minimal hang demonstrator + regression test target.
|
||||
|
||||
Returns CLEANLY when `apply()` has been called
|
||||
earlier in this process (the patched
|
||||
`_safe_drain` breaks on EOF). Spins forever
|
||||
UNPATCHED — caller should wrap with a wall-clock
|
||||
cap (e.g. `signal.alarm(N)` or `trio.fail_after`)
|
||||
to avoid hanging the test runner if regressing.
|
||||
|
||||
Used by `tests/trionics/test_patches.py` to assert
|
||||
both:
|
||||
|
||||
1. The bug exists upstream (sanity check the
|
||||
repro is real).
|
||||
2. Our patch fixes it (post-`apply()` returns
|
||||
cleanly).
|
||||
|
||||
'''
|
||||
from trio._core._wakeup_socketpair import (
|
||||
WakeupSocketpair,
|
||||
)
|
||||
ws = WakeupSocketpair()
|
||||
ws.write_sock.close()
|
||||
ws.drain() # ← targeted operation
|
||||
|
||||
|
||||
def apply() -> bool:
|
||||
'''
|
||||
Apply the EOF-break patch to
|
||||
`WakeupSocketpair.drain`. Idempotent + version-
|
||||
gated.
|
||||
|
||||
Returns:
|
||||
|
||||
- `True` if patched THIS call (inaugural apply).
|
||||
- `False` if skipped (already applied this process,
|
||||
OR `is_needed() == False` because upstream fixed
|
||||
it).
|
||||
|
||||
'''
|
||||
global _APPLIED
|
||||
if _APPLIED or not is_needed():
|
||||
return False
|
||||
|
||||
from trio._core._wakeup_socketpair import (
|
||||
WakeupSocketpair as _WSP,
|
||||
)
|
||||
|
||||
def _safe_drain(self) -> None:
|
||||
try:
|
||||
while True:
|
||||
data = self.wakeup_sock.recv(2**16)
|
||||
# XXX patch — break on EOF instead of
|
||||
# spinning. Upstream trio's `drain()`
|
||||
# only handles the `BlockingIOError`
|
||||
# (buffer-empty) case; missed the
|
||||
# peer-closed (`recv == b''`) case.
|
||||
if not data:
|
||||
return
|
||||
except BlockingIOError:
|
||||
pass
|
||||
|
||||
_WSP.drain = _safe_drain
|
||||
_APPLIED = True
|
||||
return True
|
||||
272
uv.lock
272
uv.lock
|
|
@ -1,6 +1,10 @@
|
|||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.12, <3.14"
|
||||
requires-python = ">=3.13, <3.15"
|
||||
resolution-markers = [
|
||||
"python_full_version >= '3.14'",
|
||||
"python_full_version < '3.14'",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-generator"
|
||||
|
|
@ -44,18 +48,6 @@ version = "1.0.8"
|
|||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/75/aa/abcd75e9600987a0bc6cfe9b6b2ff3f0e2cb08c170addc6e76035b5c4cb3/blake3-1.0.8.tar.gz", hash = "sha256:513cc7f0f5a7c035812604c2c852a0c1468311345573de647e310aca4ab165ba", size = 117308, upload-time = "2025-10-14T06:47:48.83Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ed/a0/b7b6dff04012cfd6e665c09ee446f749bd8ea161b00f730fe1bdecd0f033/blake3-1.0.8-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:d8da4233984d51471bd4e4366feda1d90d781e712e0a504ea54b1f2b3577557b", size = 347983, upload-time = "2025-10-14T06:45:47.214Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5b/a2/264091cac31d7ae913f1f296abc20b8da578b958ffb86100a7ce80e8bf5c/blake3-1.0.8-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1257be19f2d381c868a34cc822fc7f12f817ddc49681b6d1a2790bfbda1a9865", size = 325415, upload-time = "2025-10-14T06:45:48.482Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ee/7d/85a4c0782f613de23d114a7a78fcce270f75b193b3ff3493a0de24ba104a/blake3-1.0.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:269f255b110840e52b6ce9db02217e39660ebad3e34ddd5bca8b8d378a77e4e1", size = 371296, upload-time = "2025-10-14T06:45:49.674Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e3/20/488475254976ed93fab57c67aa80d3b40df77f7d9db6528c9274bff53e08/blake3-1.0.8-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:66ca28a673025c40db3eba21a9cac52f559f83637efa675b3f6bd8683f0415f3", size = 374516, upload-time = "2025-10-14T06:45:51.23Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7b/21/2a1c47fedb77fb396512677ec6d46caf42ac6e9a897db77edd0a2a46f7bb/blake3-1.0.8-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bcb04966537777af56c1f399b35525aa70a1225816e121ff95071c33c0f7abca", size = 447911, upload-time = "2025-10-14T06:45:52.637Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cb/7d/db0626df16029713e7e61b67314c4835e85c296d82bd907c21c6ea271da2/blake3-1.0.8-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e5b5da177d62cc4b7edf0cea08fe4dec960c9ac27f916131efa890a01f747b93", size = 505420, upload-time = "2025-10-14T06:45:54.445Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5b/55/6e737850c2d58a6d9de8a76dad2ae0f75b852a23eb4ecb07a0b165e6e436/blake3-1.0.8-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:38209b10482c97e151681ea3e91cc7141f56adbbf4820a7d701a923124b41e6a", size = 394189, upload-time = "2025-10-14T06:45:55.719Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5b/94/eafaa5cdddadc0c9c603a6a6d8339433475e1a9f60c8bb9c2eed2d8736b6/blake3-1.0.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:504d1399b7fb91dfe5c25722d2807990493185faa1917456455480c36867adb5", size = 388001, upload-time = "2025-10-14T06:45:57.067Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/17/81/735fa00d13de7f68b25e1b9cb36ff08c6f165e688d85d8ec2cbfcdedccc5/blake3-1.0.8-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c84af132aa09abeadf9a0118c8fb26f4528f3f42c10ef8be0fcf31c478774ec4", size = 550302, upload-time = "2025-10-14T06:45:58.657Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0e/c6/d1fe8bdea4a6088bd54b5a58bc40aed89a4e784cd796af7722a06f74bae7/blake3-1.0.8-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a25db3d36b55f5ed6a86470155cc749fc9c5b91c949b8d14f48658f9d960d9ec", size = 554211, upload-time = "2025-10-14T06:46:00.269Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/55/d1/ca74aa450cbe10e396e061f26f7a043891ffa1485537d6b30d3757e20995/blake3-1.0.8-cp312-cp312-win32.whl", hash = "sha256:e0fee93d5adcd44378b008c147e84f181f23715307a64f7b3db432394bbfce8b", size = 228343, upload-time = "2025-10-14T06:46:01.533Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/4d/42/bbd02647169e3fbed27558555653ac2578c6f17ccacf7d1956c58ef1d214/blake3-1.0.8-cp312-cp312-win_amd64.whl", hash = "sha256:6a6eafc29e4f478d365a87d2f25782a521870c8514bb43734ac85ae9be71caf7", size = 215704, upload-time = "2025-10-14T06:46:02.79Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/55/b8/11de9528c257f7f1633f957ccaff253b706838d22c5d2908e4735798ec01/blake3-1.0.8-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:46dc20976bd6c235959ef0246ec73420d1063c3da2839a9c87ca395cf1fd7943", size = 347771, upload-time = "2025-10-14T06:46:04.248Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/50/26/f7668be55c909678b001ecacff11ad7016cd9b4e9c7cc87b5971d638c5a9/blake3-1.0.8-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:d17eb6382634b3a5bc0c0e0454d5265b0becaeeadb6801ed25150b39a999d0cc", size = 325431, upload-time = "2025-10-14T06:46:06.136Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/77/57/e8a85fa261894bf7ce7af928ff3408aab60287ab8d58b55d13a3f700b619/blake3-1.0.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:19fc6f2b7edab8acff6895fc6e38c19bd79f4c089e21153020c75dfc7397d52d", size = 370994, upload-time = "2025-10-14T06:46:07.398Z" },
|
||||
|
|
@ -80,6 +72,30 @@ wheels = [
|
|||
{ url = "https://files.pythonhosted.org/packages/d6/65/1859fddfabc1cc72548c2269d988819aad96d854e25eae00531517925901/blake3-1.0.8-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:511133bab85ff60ed143424ce484d08c60894ff7323f685d7a6095f43f0c85c3", size = 553805, upload-time = "2025-10-14T06:46:36.532Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c1/c7/2969352017f62378e388bb07bb2191bc9a953f818dc1cd6b9dd5c24916e1/blake3-1.0.8-cp313-cp313t-win32.whl", hash = "sha256:9c9fbdacfdeb68f7ca53bb5a7a5a593ec996eaf21155ad5b08d35e6f97e60877", size = 228068, upload-time = "2025-10-14T06:46:37.826Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d8/fc/923e25ac9cadfff1cd20038bcc0854d0f98061eb6bc78e42c43615f5982d/blake3-1.0.8-cp313-cp313t-win_amd64.whl", hash = "sha256:3cec94ed5676821cf371e9c9d25a41b4f3ebdb5724719b31b2749653b7cc1dfa", size = 215369, upload-time = "2025-10-14T06:46:39.054Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2e/2a/9f13ea01b03b1b4751a1cc2b6c1ef4b782e19433a59cf35b59cafb2a2696/blake3-1.0.8-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:2c33dac2c6112bc23f961a7ca305c7e34702c8177040eb98d0389d13a347b9e1", size = 347016, upload-time = "2025-10-14T06:46:40.318Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/06/8e/8458c4285fbc5de76414f243e4e0fcab795d71a8b75324e14959aee699da/blake3-1.0.8-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c445eff665d21c3b3b44f864f849a2225b1164c08654beb23224a02f087b7ff1", size = 324496, upload-time = "2025-10-14T06:46:42.355Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/49/fa/b913eb9cc4af708c03e01e6b88a8bb3a74833ba4ae4b16b87e2829198e06/blake3-1.0.8-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a47939f04b89c5c6ff1e51e883e5efab1ea1bf01a02f4d208d216dddd63d0dd8", size = 370654, upload-time = "2025-10-14T06:46:43.907Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7f/4f/245e0800c33b99c8f2b570d9a7199b51803694913ee4897f339648502933/blake3-1.0.8-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:73e0b4fa25f6e3078526a592fb38fca85ef204fd02eced6731e1cdd9396552d4", size = 374693, upload-time = "2025-10-14T06:46:45.186Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a2/a6/8cb182c8e482071dbdfcc6ec0048271fd48bcb78782d346119ff54993700/blake3-1.0.8-cp314-cp314-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4b0543c57eb9d6dac9d4bced63e9f7f7b546886ac04cec8da3c3d9c8f30cbbb7", size = 447673, upload-time = "2025-10-14T06:46:46.358Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/06/b7/1cbbb5574d2a9436d1b15e7eb5b9d82e178adcaca71a97b0fddaca4bfe3a/blake3-1.0.8-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ed972ebd553c0c25363459e9fc71a38c045d8419e365b59acd8cd791eff13981", size = 507233, upload-time = "2025-10-14T06:46:48.109Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9c/45/b55825d90af353b3e26c653bab278da9d6563afcf66736677f9397e465be/blake3-1.0.8-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3bafdec95dfffa3f6571e529644744e280337df15ddd9728f224ba70c5779b23", size = 393852, upload-time = "2025-10-14T06:46:49.511Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/34/73/9058a1a457dd20491d1b37de53d6876eff125e1520d9b2dd7d0acbc88de2/blake3-1.0.8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2d78f06f3fb838b34c330e2987090376145cbe5944d8608a0c4779c779618f7b", size = 386442, upload-time = "2025-10-14T06:46:51.205Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/30/6d/561d537ffc17985e276e08bf4513f1c106f1fdbef571e782604dc4e44070/blake3-1.0.8-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:dd03ff08d1b6e4fdda1cd03826f971ae8966ef6f683a8c68aa27fb21904b5aa9", size = 549929, upload-time = "2025-10-14T06:46:52.494Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/03/2f/dbe20d2c57f1a67c63be4ba310bcebc707b945c902a0bde075d2a8f5cd5c/blake3-1.0.8-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:4e02a3c499e35bf51fc15b2738aca1a76410804c877bcd914752cac4f71f052a", size = 553750, upload-time = "2025-10-14T06:46:54.194Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6b/da/c6cb712663c869b2814870c2798e57289c4268c5ac5fb12d467fce244860/blake3-1.0.8-cp314-cp314-win32.whl", hash = "sha256:a585357d5d8774aad9ffc12435de457f9e35cde55e0dc8bc43ab590a6929e59f", size = 228404, upload-time = "2025-10-14T06:46:56.807Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dc/b6/c7dcd8bc3094bba1c4274e432f9e77a7df703532ca000eaa550bd066b870/blake3-1.0.8-cp314-cp314-win_amd64.whl", hash = "sha256:9ab5998e2abd9754819753bc2f1cf3edf82d95402bff46aeef45ed392a5468bf", size = 215460, upload-time = "2025-10-14T06:46:58.15Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/75/3c/6c8afd856c353176836daa5cc33a7989e8f54569e9d53eb1c53fc8f80c34/blake3-1.0.8-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:e2df12f295f95a804338bd300e8fad4a6f54fd49bd4d9c5893855a230b5188a8", size = 347482, upload-time = "2025-10-14T06:47:00.189Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6a/35/92cd5501ce8e1f5cabdc0c3ac62d69fdb13ff0b60b62abbb2b6d0a53a790/blake3-1.0.8-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:63379be58438878eeb76ebe4f0efbeaabf42b79f2cff23b6126b7991588ced67", size = 324376, upload-time = "2025-10-14T06:47:01.413Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/11/33/503b37220a3e2e31917ef13722efd00055af51c5e88ae30974c733d7ece6/blake3-1.0.8-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:88d527c247f9609dc1d45a08fd243e39f0d5300d54c57e048de24d4fa9240ebb", size = 370220, upload-time = "2025-10-14T06:47:02.573Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3e/df/fe817843adf59516c04d44387bd643b422a3b0400ea95c6ede6a49920737/blake3-1.0.8-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:506a47897a11ebe8f3cdeb52f1365d6a2f83959e98ccb0c830f8f73277d4d358", size = 373454, upload-time = "2025-10-14T06:47:03.784Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/4d/90a2a623575373dfc9b683f1bad1bf017feafa5a6d65d94fb09543050740/blake3-1.0.8-cp314-cp314t-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e5122a61b3b004bbbd979bdf83a3aaab432da3e2a842d7ddf1c273f2503b4884", size = 447102, upload-time = "2025-10-14T06:47:04.958Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/93/ff/4e8ce314f60115c4c657b1fdbe9225b991da4f5bcc5d1c1f1d151e2f39d6/blake3-1.0.8-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0171e85d56dec1219abdae5f49a0ed12cb3f86a454c29160a64fd8a8166bba37", size = 506791, upload-time = "2025-10-14T06:47:06.82Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/44/88/2963a1f18aab52bdcf35379b2b48c34bbc462320c37e76960636b8602c36/blake3-1.0.8-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:003f61e8c41dd9931edddf1cc6a1bb680fb2ac0ad15493ef4a1df9adc59ce9df", size = 393717, upload-time = "2025-10-14T06:47:09.085Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/45/d1/a848ed8e8d4e236b9b16381768c9ae99d92890c24886bb4505aa9c3d2033/blake3-1.0.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2c3151955efb09ba58cd3e1263521e15e9e3866a40d6bd3556d86fc968e8f95", size = 386150, upload-time = "2025-10-14T06:47:10.363Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/96/09/e3eb5d60f97c01de23d9f434e6e1fc117efb466eaa1f6ddbbbcb62580d6e/blake3-1.0.8-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:5eb25bca3cee2e0dd746a214784fb36be6a43640c01c55b6b4e26196e72d076c", size = 549120, upload-time = "2025-10-14T06:47:11.713Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/14/ad/3d9661c710febb8957dd685fdb3e5a861aa0ac918eda3031365ce45789e2/blake3-1.0.8-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:ab4e1dea4fa857944944db78e8f20d99ee2e16b2dea5a14f514fb0607753ac83", size = 553264, upload-time = "2025-10-14T06:47:13.317Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/11/55/e332a5b49edf377d0690e95951cca21a00c568f6e37315f9749efee52617/blake3-1.0.8-cp314-cp314t-win32.whl", hash = "sha256:67f1bc11bf59464ef092488c707b13dd4e872db36e25c453dfb6e0c7498df9f1", size = 228116, upload-time = "2025-10-14T06:47:14.516Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b0/5c/dbd00727a3dd165d7e0e8af40e630cd7e45d77b525a3218afaff8a87358e/blake3-1.0.8-cp314-cp314t-win_amd64.whl", hash = "sha256:421b99cdf1ff2d1bf703bc56c454f4b286fce68454dd8711abbcb5a0df90c19a", size = 215133, upload-time = "2025-10-14T06:47:16.069Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -91,17 +107,6 @@ dependencies = [
|
|||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/fc/97/c783634659c2920c3fc70419e3af40972dbaf758daa229a7d6ea6135c90d/cffi-1.17.1.tar.gz", hash = "sha256:1c39c6016c32bc48dd54561950ebd6836e1670f2ae46128f67cf49e789c52824", size = 516621, upload-time = "2024-09-04T20:45:21.852Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/5a/84/e94227139ee5fb4d600a7a4927f322e1d4aea6fdc50bd3fca8493caba23f/cffi-1.17.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:805b4371bf7197c329fcb3ead37e710d1bca9da5d583f5073b799d5c5bd1eee4", size = 183178, upload-time = "2024-09-04T20:44:12.232Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/da/ee/fb72c2b48656111c4ef27f0f91da355e130a923473bf5ee75c5643d00cca/cffi-1.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:733e99bc2df47476e3848417c5a4540522f234dfd4ef3ab7fafdf555b082ec0c", size = 178840, upload-time = "2024-09-04T20:44:13.739Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cc/b6/db007700f67d151abadf508cbfd6a1884f57eab90b1bb985c4c8c02b0f28/cffi-1.17.1-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1257bdabf294dceb59f5e70c64a3e2f462c30c7ad68092d01bbbfb1c16b1ba36", size = 454803, upload-time = "2024-09-04T20:44:15.231Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1a/df/f8d151540d8c200eb1c6fba8cd0dfd40904f1b0682ea705c36e6c2e97ab3/cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da95af8214998d77a98cc14e3a3bd00aa191526343078b530ceb0bd710fb48a5", size = 478850, upload-time = "2024-09-04T20:44:17.188Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/28/c0/b31116332a547fd2677ae5b78a2ef662dfc8023d67f41b2a83f7c2aa78b1/cffi-1.17.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d63afe322132c194cf832bfec0dc69a99fb9bb6bbd550f161a49e9e855cc78ff", size = 485729, upload-time = "2024-09-04T20:44:18.688Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/91/2b/9a1ddfa5c7f13cab007a2c9cc295b70fbbda7cb10a286aa6810338e60ea1/cffi-1.17.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f79fc4fc25f1c8698ff97788206bb3c2598949bfe0fef03d299eb1b5356ada99", size = 471256, upload-time = "2024-09-04T20:44:20.248Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b2/d5/da47df7004cb17e4955df6a43d14b3b4ae77737dff8bf7f8f333196717bf/cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b62ce867176a75d03a665bad002af8e6d54644fad99a3c70905c543130e39d93", size = 479424, upload-time = "2024-09-04T20:44:21.673Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0b/ac/2a28bcf513e93a219c8a4e8e125534f4f6db03e3179ba1c45e949b76212c/cffi-1.17.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:386c8bf53c502fff58903061338ce4f4950cbdcb23e2902d86c0f722b786bbe3", size = 484568, upload-time = "2024-09-04T20:44:23.245Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d4/38/ca8a4f639065f14ae0f1d9751e70447a261f1a30fa7547a828ae08142465/cffi-1.17.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4ceb10419a9adf4460ea14cfd6bc43d08701f0835e979bf821052f1805850fe8", size = 488736, upload-time = "2024-09-04T20:44:24.757Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/86/c5/28b2d6f799ec0bdecf44dced2ec5ed43e0eb63097b0f58c293583b406582/cffi-1.17.1-cp312-cp312-win32.whl", hash = "sha256:a08d7e755f8ed21095a310a693525137cfe756ce62d066e53f502a83dc550f65", size = 172448, upload-time = "2024-09-04T20:44:26.208Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/50/b9/db34c4755a7bd1cb2d1603ac3863f22bcecbd1ba29e5ee841a4bc510b294/cffi-1.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:51392eae71afec0d0c8fb1a53b204dbb3bcabcb3c9b807eedf3e1e6ccf2de903", size = 181976, upload-time = "2024-09-04T20:44:27.578Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8d/f8/dd6c246b148639254dad4d6803eb6a54e8c85c6e11ec9df2cffa87571dbe/cffi-1.17.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f3a2b4222ce6b60e2e8b337bb9596923045681d71e5a082783484d845390938e", size = 182989, upload-time = "2024-09-04T20:44:28.956Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8b/f1/672d303ddf17c24fc83afd712316fda78dc6fce1cd53011b839483e1ecc8/cffi-1.17.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0984a4925a435b1da406122d4d7968dd861c1385afe3b45ba82b750f229811e2", size = 178802, upload-time = "2024-09-04T20:44:30.289Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0e/2d/eab2e858a91fdff70533cab61dcff4a1f55ec60425832ddfdc9cd36bc8af/cffi-1.17.1-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d01b12eeeb4427d3110de311e1774046ad344f5b1a7403101878976ecd7a10f3", size = 454792, upload-time = "2024-09-04T20:44:32.01Z" },
|
||||
|
|
@ -150,9 +155,9 @@ name = "greenback"
|
|||
version = "1.2.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "greenlet" },
|
||||
{ name = "outcome" },
|
||||
{ name = "sniffio" },
|
||||
{ name = "greenlet", marker = "python_full_version < '3.14'" },
|
||||
{ name = "outcome", marker = "python_full_version < '3.14'" },
|
||||
{ name = "sniffio", marker = "python_full_version < '3.14'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/dc/c1/ab3a42c0f3ed56df9cd33de1539b3198d98c6ccbaf88a73d6be0b72d85e0/greenback-1.2.1.tar.gz", hash = "sha256:de3ca656885c03b96dab36079f3de74bb5ba061da9bfe3bb69dccc866ef95ea3", size = 42597, upload-time = "2024-02-20T21:23:13.239Z" }
|
||||
wheels = [
|
||||
|
|
@ -165,15 +170,6 @@ version = "3.1.1"
|
|||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/2f/ff/df5fede753cc10f6a5be0931204ea30c35fa2f2ea7a35b25bdaf4fe40e46/greenlet-3.1.1.tar.gz", hash = "sha256:4ce3ac6cdb6adf7946475d7ef31777c26d94bccc377e070a7986bd2d5c515467", size = 186022, upload-time = "2024-09-20T18:21:04.506Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/7d/ec/bad1ac26764d26aa1353216fcbfa4670050f66d445448aafa227f8b16e80/greenlet-3.1.1-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:4afe7ea89de619adc868e087b4d2359282058479d7cfb94970adf4b55284574d", size = 274260, upload-time = "2024-09-20T17:08:07.301Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/66/d4/c8c04958870f482459ab5956c2942c4ec35cac7fe245527f1039837c17a9/greenlet-3.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f406b22b7c9a9b4f8aa9d2ab13d6ae0ac3e85c9a809bd590ad53fed2bf70dc79", size = 649064, upload-time = "2024-09-20T17:36:47.628Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/51/41/467b12a8c7c1303d20abcca145db2be4e6cd50a951fa30af48b6ec607581/greenlet-3.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c3a701fe5a9695b238503ce5bbe8218e03c3bcccf7e204e455e7462d770268aa", size = 663420, upload-time = "2024-09-20T17:39:21.258Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/27/8f/2a93cd9b1e7107d5c7b3b7816eeadcac2ebcaf6d6513df9abaf0334777f6/greenlet-3.1.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2846930c65b47d70b9d178e89c7e1a69c95c1f68ea5aa0a58646b7a96df12441", size = 658035, upload-time = "2024-09-20T17:44:26.501Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/57/5c/7c6f50cb12be092e1dccb2599be5a942c3416dbcfb76efcf54b3f8be4d8d/greenlet-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99cfaa2110534e2cf3ba31a7abcac9d328d1d9f1b95beede58294a60348fba36", size = 660105, upload-time = "2024-09-20T17:08:42.048Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f1/66/033e58a50fd9ec9df00a8671c74f1f3a320564c6415a4ed82a1c651654ba/greenlet-3.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1443279c19fca463fc33e65ef2a935a5b09bb90f978beab37729e1c3c6c25fe9", size = 613077, upload-time = "2024-09-20T17:08:33.707Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/19/c5/36384a06f748044d06bdd8776e231fadf92fc896bd12cb1c9f5a1bda9578/greenlet-3.1.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:b7cede291382a78f7bb5f04a529cb18e068dd29e0fb27376074b6d0317bf4dd0", size = 1135975, upload-time = "2024-09-20T17:44:15.989Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/38/f9/c0a0eb61bdf808d23266ecf1d63309f0e1471f284300ce6dac0ae1231881/greenlet-3.1.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:23f20bb60ae298d7d8656c6ec6db134bca379ecefadb0b19ce6f19d1f232a942", size = 1163955, upload-time = "2024-09-20T17:09:25.539Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/43/21/a5d9df1d21514883333fc86584c07c2b49ba7c602e670b174bd73cfc9c7f/greenlet-3.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:7124e16b4c55d417577c2077be379514321916d5790fa287c9ed6f23bd2ffd01", size = 299655, upload-time = "2024-09-20T17:21:22.427Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f3/57/0db4940cd7bb461365ca8d6fd53e68254c9dbbcc2b452e69d0d41f10a85e/greenlet-3.1.1-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:05175c27cb459dcfc05d026c4232f9de8913ed006d42713cb8a5137bd49375f1", size = 272990, upload-time = "2024-09-20T17:08:26.312Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1c/ec/423d113c9f74e5e402e175b157203e9102feeb7088cee844d735b28ef963/greenlet-3.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:935e943ec47c4afab8965954bf49bfa639c05d4ccf9ef6e924188f762145c0ff", size = 649175, upload-time = "2024-09-20T17:36:48.983Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a9/46/ddbd2db9ff209186b7b7c621d1432e2f21714adc988703dbdd0e65155c77/greenlet-3.1.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:667a9706c970cb552ede35aee17339a18e8f2a87a51fba2ed39ceeeb1004798a", size = 663425, upload-time = "2024-09-20T17:39:22.705Z" },
|
||||
|
|
@ -228,22 +224,6 @@ version = "5.2.1"
|
|||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/91/1a/edb23803a168f070ded7a3014c6d706f63b90c84ccc024f89d794a3b7a6d/mmh3-5.2.1.tar.gz", hash = "sha256:bbea5b775f0ac84945191fb83f845a6fd9a21a03ea7f2e187defac7e401616ad", size = 33775, upload-time = "2026-03-05T15:55:57.716Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/92/94/bc5c3b573b40a328c4d141c20e399039ada95e5e2a661df3425c5165fd84/mmh3-5.2.1-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:0cc21533878e5586b80d74c281d7f8da7932bc8ace50b8d5f6dbf7e3935f63f1", size = 56087, upload-time = "2026-03-05T15:54:21.92Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f6/80/64a02cc3e95c3af0aaa2590849d9ed24a9f14bb93537addde688e039b7c3/mmh3-5.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4eda76074cfca2787c8cf1bec603eaebdddd8b061ad5502f85cddae998d54f00", size = 40500, upload-time = "2026-03-05T15:54:22.953Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8b/72/e6d6602ce18adf4ddcd0e48f2e13590cc92a536199e52109f46f259d3c46/mmh3-5.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:eee884572b06bbe8a2b54f424dbd996139442cf83c76478e1ec162512e0dd2c7", size = 40034, upload-time = "2026-03-05T15:54:23.943Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/59/c2/bf4537a8e58e21886ef16477041238cab5095c836496e19fafc34b7445d2/mmh3-5.2.1-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:0d0b7e803191db5f714d264044e06189c8ccd3219e936cc184f07106bd17fd7b", size = 97292, upload-time = "2026-03-05T15:54:25.335Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e5/e2/51ed62063b44d10b06d975ac87af287729eeb5e3ed9772f7584a17983e90/mmh3-5.2.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:8e6c219e375f6341d0959af814296372d265a8ca1af63825f65e2e87c618f006", size = 103274, upload-time = "2026-03-05T15:54:26.44Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/75/ce/12a7524dca59eec92e5b31fdb13ede1e98eda277cf2b786cf73bfbc24e81/mmh3-5.2.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:26fb5b9c3946bf7f1daed7b37e0c03898a6f062149127570f8ede346390a0825", size = 106158, upload-time = "2026-03-05T15:54:28.578Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/86/1f/d3ba6dd322d01ab5d44c46c8f0c38ab6bbbf9b5e20e666dfc05bf4a23604/mmh3-5.2.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3c38d142c706201db5b2345166eeef1e7740e3e2422b470b8ba5c8727a9b4c7a", size = 113005, upload-time = "2026-03-05T15:54:29.767Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b6/a9/15d6b6f913294ea41b44d901741298e3718e1cb89ee626b3694625826a43/mmh3-5.2.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:50885073e2909251d4718634a191c49ae5f527e5e1736d738e365c3e8be8f22b", size = 120744, upload-time = "2026-03-05T15:54:30.931Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/76/b3/70b73923fd0284c439860ff5c871b20210dfdbe9a6b9dd0ee6496d77f174/mmh3-5.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:b3f99e1756fc48ad507b95e5d86f2fb21b3d495012ff13e6592ebac14033f166", size = 99111, upload-time = "2026-03-05T15:54:32.353Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dd/38/99f7f75cd27d10d8b899a1caafb9d531f3903e4d54d572220e3d8ac35e89/mmh3-5.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:62815d2c67f2dd1be76a253d88af4e1da19aeaa1820146dec52cf8bee2958b16", size = 98623, upload-time = "2026-03-05T15:54:33.801Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fd/68/6e292c0853e204c44d2f03ea5f090be3317a0e2d9417ecb62c9eb27687df/mmh3-5.2.1-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:8f767ba0911602ddef289404e33835a61168314ebd3c729833db2ed685824211", size = 106437, upload-time = "2026-03-05T15:54:35.177Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dd/c6/fedd7284c459cfb58721d461fcf5607a4c1f5d9ab195d113d51d10164d16/mmh3-5.2.1-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:67e41a497bac88cc1de96eeba56eeb933c39d54bc227352f8455aa87c4ca4000", size = 110002, upload-time = "2026-03-05T15:54:36.673Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/ac/ca8e0c19a34f5b71390171d2ff0b9f7f187550d66801a731bb68925126a4/mmh3-5.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:3d74a03fb57757ece25aa4b3c1c60157a1cece37a020542785f942e2f827eed5", size = 97507, upload-time = "2026-03-05T15:54:37.804Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/df/94/6ebb9094cfc7ac5e7950776b9d13a66bb4a34f83814f32ba2abc9494fc68/mmh3-5.2.1-cp312-cp312-win32.whl", hash = "sha256:7374d6e3ef72afe49697ecd683f3da12f4fc06af2d75433d0580c6746d2fa025", size = 40773, upload-time = "2026-03-05T15:54:40.077Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5b/3c/cd3527198cf159495966551c84a5f36805a10ac17b294f41f67b83f6a4d6/mmh3-5.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:3a9fed49c6ce4ed7e73f13182760c65c816da006debe67f37635580dfb0fae00", size = 41560, upload-time = "2026-03-05T15:54:41.148Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/15/96/6fe5ebd0f970a076e3ed5512871ce7569447b962e96c125528a2f9724470/mmh3-5.2.1-cp312-cp312-win_arm64.whl", hash = "sha256:bbfcb95d9a744e6e2827dfc66ad10e1020e0cac255eb7f85652832d5a264c2fc", size = 39313, upload-time = "2026-03-05T15:54:42.171Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/25/a5/9daa0508a1569a54130f6198d5462a92deda870043624aa3ea72721aa765/mmh3-5.2.1-cp313-cp313-android_21_arm64_v8a.whl", hash = "sha256:723b2681ed4cc07d3401bbea9c201ad4f2a4ca6ba8cddaff6789f715dd2b391e", size = 40832, upload-time = "2026-03-05T15:54:43.212Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0a/6b/3230c6d80c1f4b766dedf280a92c2241e99f87c1504ff74205ec8cebe451/mmh3-5.2.1-cp313-cp313-android_21_x86_64.whl", hash = "sha256:3619473a0e0d329fd4aec8075628f8f616be2da41605300696206d6f36920c3d", size = 41964, upload-time = "2026-03-05T15:54:44.204Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/62/fb/648bfddb74a872004b6ee751551bfdda783fe6d70d2e9723bad84dbe5311/mmh3-5.2.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:e48d4dbe0f88e53081da605ae68644e5182752803bbc2beb228cca7f1c4454d6", size = 39114, upload-time = "2026-03-05T15:54:45.205Z" },
|
||||
|
|
@ -265,6 +245,43 @@ wheels = [
|
|||
{ url = "https://files.pythonhosted.org/packages/4b/f9/dc3787ee5c813cc27fe79f45ad4500d9b5437f23a7402435cc34e07c7718/mmh3-5.2.1-cp313-cp313-win32.whl", hash = "sha256:54b64fb2433bc71488e7a449603bf8bd31fbcf9cb56fbe1eb6d459e90b86c37b", size = 40769, upload-time = "2026-03-05T15:55:05.277Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/43/67/850e0b5a1e97799822ebfc4ca0e8c6ece3ed8baf7dcdf64de817dfdda2ca/mmh3-5.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:cae6383181f1e345317742d2ddd88f9e7d2682fa4c9432e3a74e47d92dce0229", size = 41563, upload-time = "2026-03-05T15:55:06.283Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c0/cc/98c90b28e1da5458e19fbfaf4adb5289208d3bfccd45dd14eab216a2f0bb/mmh3-5.2.1-cp313-cp313-win_arm64.whl", hash = "sha256:022aa1a528604e6c83d0a7705fdef0b5355d897a9e0fa3a8d26709ceaa06965d", size = 39310, upload-time = "2026-03-05T15:55:07.323Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/63/b4/65bc1fb2bb7f83e91c30865023b1847cf89a5f237165575e8c83aa536584/mmh3-5.2.1-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:d771f085fcdf4035786adfb1d8db026df1eb4b41dac1c3d070d1e49512843227", size = 40794, upload-time = "2026-03-05T15:55:09.773Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c4/86/7168b3d83be8eb553897b1fac9da8bbb06568e5cfe555ffc329ebb46f59d/mmh3-5.2.1-cp314-cp314-android_24_x86_64.whl", hash = "sha256:7f196cd7910d71e9d9860da0ff7a77f64d22c1ad931f1dd18559a06e03109fc0", size = 41923, upload-time = "2026-03-05T15:55:10.924Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bf/9b/b653ab611c9060ce8ff0ba25c0226757755725e789292f3ca138a58082cd/mmh3-5.2.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b1f12bd684887a0a5d55e6363ca87056f361e45451105012d329b86ec19dbe0b", size = 39131, upload-time = "2026-03-05T15:55:11.961Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9b/b4/5a2e0d34ab4d33543f01121e832395ea510132ea8e52cdf63926d9d81754/mmh3-5.2.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:d106493a60dcb4aef35a0fac85105e150a11cf8bc2b0d388f5a33272d756c966", size = 39825, upload-time = "2026-03-05T15:55:13.013Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bd/69/81699a8f39a3f8d368bec6443435c0c392df0d200ad915bf0d222b588e03/mmh3-5.2.1-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:44983e45310ee5b9f73397350251cdf6e63a466406a105f1d16cb5baa659270b", size = 40344, upload-time = "2026-03-05T15:55:14.026Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0c/b3/71c8c775807606e8fd8acc5c69016e1caf3200d50b50b6dd4b40ce10b76c/mmh3-5.2.1-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:368625fb01666655985391dbad3860dc0ba7c0d6b9125819f3121ee7292b4ac8", size = 56291, upload-time = "2026-03-05T15:55:15.137Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6f/75/2c24517d4b2ce9e4917362d24f274d3d541346af764430249ddcc4cb3a08/mmh3-5.2.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:72d1cc63bcc91e14933f77d51b3df899d6a07d184ec515ea7f56bff659e124d7", size = 40575, upload-time = "2026-03-05T15:55:16.518Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bf/b9/e4a360164365ac9f07a25f0f7928e3a66eb9ecc989384060747aa170e6aa/mmh3-5.2.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:e8b4b5580280b9265af3e0409974fb79c64cf7523632d03fbf11df18f8b0181e", size = 40052, upload-time = "2026-03-05T15:55:17.735Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/97/ca/120d92223a7546131bbbc31c9174168ee7a73b1366f5463ffe69d9e691fe/mmh3-5.2.1-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:4cbbde66f1183db040daede83dd86c06d663c5bb2af6de1142b7c8c37923dd74", size = 97311, upload-time = "2026-03-05T15:55:18.959Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b6/71/c1a60c1652b8813ef9de6d289784847355417ee0f2980bca002fe87f4ae5/mmh3-5.2.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:8ff038d52ef6aa0f309feeba00c5095c9118d0abf787e8e8454d6048db2037fc", size = 103279, upload-time = "2026-03-05T15:55:20.448Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/48/29/ad97f4be1509cdcb28ae32c15593ce7c415db47ace37f8fad35b493faa9a/mmh3-5.2.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a4130d0b9ce5fad6af07421b1aecc7e079519f70d6c05729ab871794eded8617", size = 106290, upload-time = "2026-03-05T15:55:21.6Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/77/29/1f86d22e281bd8827ba373600a4a8b0c0eae5ca6aa55b9a8c26d2a34decc/mmh3-5.2.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:f6e0bfe77d238308839699944164b96a2eeccaf55f2af400f54dc20669d8d5f2", size = 113116, upload-time = "2026-03-05T15:55:22.826Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a7/7c/339971ea7ed4c12d98f421f13db3ea576a9114082ccb59d2d1a0f00ccac1/mmh3-5.2.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:f963eafc0a77a6c0562397da004f5876a9bcf7265a7bcc3205e29636bc4a1312", size = 120740, upload-time = "2026-03-05T15:55:24.3Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e4/92/3c7c4bdb8e926bb3c972d1e2907d77960c1c4b250b41e8366cf20c6e4373/mmh3-5.2.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:92883836caf50d5255be03d988d75bc93e3f86ba247b7ca137347c323f731deb", size = 99143, upload-time = "2026-03-05T15:55:25.456Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/df/0a/33dd8706e732458c8375eae63c981292de07a406bad4ec03e5269654aa2c/mmh3-5.2.1-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:57b52603e89355ff318025dd55158f6e71396c0f1f609d548e9ea9c94cc6ce0a", size = 98703, upload-time = "2026-03-05T15:55:26.723Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/51/04/76bbce05df76cbc3d396f13b2ea5b1578ef02b6a5187e132c6c33f99d596/mmh3-5.2.1-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:f40a95186a72fa0b67d15fef0f157bfcda00b4f59c8a07cbe5530d41ac35d105", size = 106484, upload-time = "2026-03-05T15:55:28.214Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d3/8f/c6e204a2c70b719c1f62ffd9da27aef2dddcba875ea9c31ca0e87b975a46/mmh3-5.2.1-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:58370d05d033ee97224c81263af123dea3d931025030fd34b61227a768a8858a", size = 110012, upload-time = "2026-03-05T15:55:29.532Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e3/37/7181efd8e39db386c1ebc3e6b7d1f702a09d7c1197a6f2742ed6b5c16597/mmh3-5.2.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:7be6dfb49e48fd0a7d91ff758a2b51336f1cd21f9d44b20f6801f072bd080cdd", size = 97508, upload-time = "2026-03-05T15:55:31.01Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/42/0f/afa7ca2615fd85e1469474bb860e381443d0b868c083b62b41cb1d7ca32f/mmh3-5.2.1-cp314-cp314-win32.whl", hash = "sha256:54fe8518abe06a4c3852754bfd498b30cc58e667f376c513eac89a244ce781a4", size = 41387, upload-time = "2026-03-05T15:55:32.403Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/0d/46d42a260ee1357db3d486e6c7a692e303c017968e14865e00efa10d09fc/mmh3-5.2.1-cp314-cp314-win_amd64.whl", hash = "sha256:3f796b535008708846044c43302719c6956f39ca2d93f2edda5319e79a29efbb", size = 42101, upload-time = "2026-03-05T15:55:33.646Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a4/7b/848a8378059d96501a41159fca90d6a99e89736b0afbe8e8edffeac8c74b/mmh3-5.2.1-cp314-cp314-win_arm64.whl", hash = "sha256:cd471ede0d802dd936b6fab28188302b2d497f68436025857ca72cd3810423fe", size = 39836, upload-time = "2026-03-05T15:55:35.026Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/27/61/1dabea76c011ba8547c25d30c91c0ec22544487a8750997a27a0c9e1180b/mmh3-5.2.1-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:5174a697ce042fa77c407e05efe41e03aa56dae9ec67388055820fb48cf4c3ba", size = 57727, upload-time = "2026-03-05T15:55:36.162Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b7/32/731185950d1cf2d5e28979cc8593016ba1619a295faba10dda664a4931b5/mmh3-5.2.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:0a3984146e414684a6be2862d84fcb1035f4984851cb81b26d933bab6119bf00", size = 41308, upload-time = "2026-03-05T15:55:37.254Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/76/aa/66c76801c24b8c9418b4edde9b5e57c75e72c94e29c48f707e3962534f18/mmh3-5.2.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:bd6e7d363aa93bd3421b30b6af97064daf47bc96005bddba67c5ffbc6df426b8", size = 40758, upload-time = "2026-03-05T15:55:38.61Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9e/bb/79a1f638a02f0ae389f706d13891e2fbf7d8c0a22ecde67ba828951bb60a/mmh3-5.2.1-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:113f78e7463a36dbbcea05bfe688efd7fa759d0f0c56e73c974d60dcfec3dfcc", size = 109670, upload-time = "2026-03-05T15:55:40.13Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/26/94/8cd0e187a288985bcfc79bf5144d1d712df9dee74365f59d26e3a1865be6/mmh3-5.2.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7e8ec5f606e0809426d2440e0683509fb605a8820a21ebd120dcdba61b74ef7f", size = 117399, upload-time = "2026-03-05T15:55:42.076Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/42/94/dfea6059bd5c5beda565f58a4096e43f4858fb6d2862806b8bbd12cbb284/mmh3-5.2.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:22b0f9971ec4e07e8223f2beebe96a6cfc779d940b6f27d26604040dd74d3a44", size = 120386, upload-time = "2026-03-05T15:55:43.481Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/47/cb/f9c45e62aaa67220179f487772461d891bb582bb2f9783c944832c60efd9/mmh3-5.2.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:85ffc9920ffc39c5eee1e3ac9100c913a0973996fbad5111f939bbda49204bb7", size = 125924, upload-time = "2026-03-05T15:55:44.638Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a5/83/fe54a4a7c11bc9f623dfc1707decd034245602b076dfc1dcc771a4163170/mmh3-5.2.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:7aec798c2b01aaa65a55f1124f3405804184373abb318a3091325aece235f67c", size = 135280, upload-time = "2026-03-05T15:55:45.866Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/97/67/fe7e9e9c143daddd210cd22aef89cbc425d58ecf238d2b7d9eb0da974105/mmh3-5.2.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:55dbbd8ffbc40d1697d5e2d0375b08599dae8746b0b08dea05eee4ce81648fac", size = 110050, upload-time = "2026-03-05T15:55:47.074Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/43/c4/6d4b09fcbef80794de447c9378e39eefc047156b290fa3dd2d5257ca8227/mmh3-5.2.1-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:6c85c38a279ca9295a69b9b088a2e48aa49737bb1b34e6a9dc6297c110e8d912", size = 111158, upload-time = "2026-03-05T15:55:48.239Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/81/a6/ca51c864bdb30524beb055a6d8826db3906af0834ec8c41d097a6e8573d5/mmh3-5.2.1-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:6290289fa5fb4c70fd7f72016e03633d60388185483ff3b162912c81205ae2cf", size = 116890, upload-time = "2026-03-05T15:55:49.405Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cc/04/5a1fe2e2ad843d03e89af25238cbc4f6840a8bb6c4329a98ab694c71deda/mmh3-5.2.1-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:4fc6cd65dc4d2fdb2625e288939a3566e36127a84811a4913f02f3d5931da52d", size = 123121, upload-time = "2026-03-05T15:55:50.61Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/af/4d/3c820c6f4897afd25905270a9f2330a23f77a207ea7356f7aadace7273c0/mmh3-5.2.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:623f938f6a039536cc02b7582a07a080f13fdfd48f87e63201d92d7e34d09a18", size = 110187, upload-time = "2026-03-05T15:55:52.143Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/21/54/1d71cd143752361c0aebef16ad3f55926a6faf7b112d355745c1f8a25f7f/mmh3-5.2.1-cp314-cp314t-win32.whl", hash = "sha256:29bc3973676ae334412efdd367fcd11d036b7be3efc1ce2407ef8676dabfeb82", size = 41934, upload-time = "2026-03-05T15:55:53.564Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9d/e4/63a2a88f31d93dea03947cccc2a076946857e799ea4f7acdecbf43b324aa/mmh3-5.2.1-cp314-cp314t-win_amd64.whl", hash = "sha256:28cfab66577000b9505a0d068c731aee7ca85cd26d4d63881fab17857e0fe1fb", size = 43036, upload-time = "2026-03-05T15:55:55.252Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a0/0f/59204bf136d1201f8d7884cfbaf7498c5b4674e87a4c693f9bde63741ce1/mmh3-5.2.1-cp314-cp314t-win_arm64.whl", hash = "sha256:dfd51b4c56b673dfbc43d7d27ef857dd91124801e2806c69bb45585ce0fa019b", size = 40391, upload-time = "2026-03-05T15:55:56.697Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -281,14 +298,6 @@ version = "0.21.1"
|
|||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e3/60/f79b9b013a16fa3a58350c9295ddc6789f2e335f36ea61ed10a21b215364/msgspec-0.21.1.tar.gz", hash = "sha256:2313508e394b0d208f8f56892ca9b2799e2561329de9763b19619595a6c0f72c", size = 319193, upload-time = "2026-04-12T21:44:50.394Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/6e/cf/317224852c00248c620a9bcf4b26e2e4ab8afd752f18d2a6ef73ebd423b6/msgspec-0.21.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d4248cf0b6129b7d230eacd493c17cc2d4f3989f3bb7f633a928a85b7dcfa251", size = 196188, upload-time = "2026-04-12T21:44:07.181Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6d/81/074612945c0666078f7366f40000013de9f6ba687491d450df699bceebc9/msgspec-0.21.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5102c7e9b3acff82178449b85006d96310e690291bb1ea0142f1b24bcb8aabcb", size = 188473, upload-time = "2026-04-12T21:44:08.736Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8a/37/655101799590bcc5fddb2bd3fe0e6194e816c2d1da7c361725f5eb89a910/msgspec-0.21.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:846758412e9518252b2ac9bffd6f0e54d9ff614f5f9488df7749f81ff5c80920", size = 218871, upload-time = "2026-04-12T21:44:09.917Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/d1/d4cd9fe89c7d400d7a18f86ccc94daa3f0927f53558846fcb60791dce5d6/msgspec-0.21.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:21995e74b5c598c2e004110ad66ec7f1b8c20bf2bcf3b2de8fd9a3094422d3ff", size = 225025, upload-time = "2026-04-12T21:44:11.191Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/24/bf/e20549e602b9edccadeeff98760345a416f9cce846a657e8b18e3396b212/msgspec-0.21.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6129f0cca52992e898fd5344187f7c8127b63d810b2fd73e36fca73b4c6475ee", size = 222672, upload-time = "2026-04-12T21:44:12.481Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b4/68/04d7a8f0f786545cf9b8c280c57aa6befb5977af6e884b8b54191cbe44b3/msgspec-0.21.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ef3ec2296248d1f8b9231acb051b6d471dfde8f21819e86c9adaaa9f42918521", size = 227303, upload-time = "2026-04-12T21:44:13.709Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cc/4d/619866af2840875be408047bf9e70ceafbae6ab50660de7134ed1b25eb86/msgspec-0.21.1-cp312-cp312-win_amd64.whl", hash = "sha256:d4ab834a054c6f0cbeef6df9e7e1b33d5f1bc7b86dea1d2fd7cad003873e783d", size = 190017, upload-time = "2026-04-12T21:44:14.977Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5e/2e/a8f9eca8fd00e097d7a9e99ba8a4685db994494448e3d4f0b7f6e9a3c0f7/msgspec-0.21.1-cp312-cp312-win_arm64.whl", hash = "sha256:628aaa35c74950a8c59da330d7e98917e1c7188f983745782027748ee4ca573e", size = 175345, upload-time = "2026-04-12T21:44:16.431Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7e/74/f11ede02839b19ff459f88e3145df5d711626ca84da4e23520cebf819367/msgspec-0.21.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:764173717a01743f007e9f74520ed281f24672c604514f7d76c1c3a10e8edb66", size = 196176, upload-time = "2026-04-12T21:44:17.613Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bb/40/4476c1bd341418a046c4955aff632ec769315d1e3cb94e6acf86d461f9ed/msgspec-0.21.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:344c7cd0eaed1fb81d7959f99100ef71ec9b536881a376f11b9a6c4803365697", size = 188524, upload-time = "2026-04-12T21:44:18.815Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ca/d9/9e9d7d7e5061b47540d03d640fab9b3965ba7ae49c1b2154861c8f007518/msgspec-0.21.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:48943e278b3854c2f89f955ddc6f9f430d3f0784b16e47d10604ee0463cd21f5", size = 218880, upload-time = "2026-04-12T21:44:20.028Z" },
|
||||
|
|
@ -297,6 +306,22 @@ wheels = [
|
|||
{ url = "https://files.pythonhosted.org/packages/4e/27/0bba04b2b4ef05f3d068429410bc71d2cea925f1596a8f41152cccd5edb8/msgspec-0.21.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:38fe93e86b61328fe544cb7fd871fad5a27c8734bfda90f65e5dbe288ae50f61", size = 227259, upload-time = "2026-04-12T21:44:24.11Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b0/2d/09574b0eea02fed2c2c1383dbaae2c7f79dc16dcd6487a886000afb5d7c4/msgspec-0.21.1-cp313-cp313-win_amd64.whl", hash = "sha256:8bc666331c35fcce05a7cd2d6221adbe0f6058f8e750711413d22793c080ac6a", size = 189857, upload-time = "2026-04-12T21:44:25.359Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/46/34/105b1576ad182879914f0c821f17ee1d13abb165cb060448f96fe2aff078/msgspec-0.21.1-cp313-cp313-win_arm64.whl", hash = "sha256:42bb1241e0750c1a4346f2aa84db26c5ffd99a4eb3a954927d9f149ff2f42898", size = 175403, upload-time = "2026-04-12T21:44:26.608Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5a/ad/86954e987d1d6a5c579e2c2e7832b65e0fff194179fdac4f581536086024/msgspec-0.21.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:fab48eb45fdbfbdb2c0edfec00ffc53b6b6085beefc6b50b61e01659f9f8757f", size = 196261, upload-time = "2026-04-12T21:44:27.807Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/a1/c5e46c3e42b866199365e35d11dddfd1fbd8bba4fdb3c52f965b1607ce94/msgspec-0.21.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:3cb779ea0c35bc807ff941d415875c1f69ca0be91a2e907ab99a171811d86a9a", size = 188729, upload-time = "2026-04-12T21:44:28.99Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/85/7d/1e29a319d678d6cb962ae5bdf32a6858ebdf38f73bc654c0e9c742a0c2c8/msgspec-0.21.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:68604db36b3b4dd9bf160e436e12798a4738848144cea1aca1cb984011eb160f", size = 219866, upload-time = "2026-04-12T21:44:31.104Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/25/1f/cca084ca2572810fff12ea9dbdcbe39eac048f40daf4a9077b49fcbe8cee/msgspec-0.21.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3d6b9dc50948eaf65df54d2fd0ff66e6d8c32f116037209ee861810eb9b676cb", size = 224993, upload-time = "2026-04-12T21:44:32.649Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/94/d2120fc9d419a89a3a7c13e5b7078798c4b392a96a02a6e2b3ce43a8766c/msgspec-0.21.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:52c5e21930942302394429c5a582ce7e6b62c7f983b3760834c2ce107e0dd6df", size = 223535, upload-time = "2026-04-12T21:44:33.839Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/75/17/42418b66a3ad972a89bab73dd78b79cc6282bb488a25e73c853cee7443b9/msgspec-0.21.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:abbb39d65681fa24ed394e01af3d59d869068324f900c61d06062b7fb9980f2f", size = 227222, upload-time = "2026-04-12T21:44:35.093Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c4/33/265c894268cca88ff67b144ca2b4c522fc8b9a6f1966a3640c70516e78e1/msgspec-0.21.1-cp314-cp314-win_amd64.whl", hash = "sha256:5666b1b560b97b6ec2eb3fca8a502298ebac56e13bbca1f88523538ce83d01ea", size = 193810, upload-time = "2026-04-12T21:44:36.612Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/8f/a6d35f25bf1fc63c492fdd88fdce01ba0875ead48c2b91f90f33653b4131/msgspec-0.21.1-cp314-cp314-win_arm64.whl", hash = "sha256:d8b8578e4c83b14ceea4cef0d0b747e31d9330fe4b03b2b2ad4063866a178f93", size = 179125, upload-time = "2026-04-12T21:44:38.198Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c6/39/74839641e64b99d87da55af0fc472854d42b46e2183b9e2a67fe1bb2a512/msgspec-0.21.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:15f523d51c00ebad412213bfe9f06f0a50ec2b93e0c19e824a2d267cabb48ea2", size = 200171, upload-time = "2026-04-12T21:44:39.414Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/70/9b/ce0cca6d2d87fcd4b6ff97600790494e64f26a2c55d61507cd2755c16193/msgspec-0.21.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:4e47390360583ba3d5c6cb44cf0a9f61b0a06a899d3c2c00627cedebb2e2884b", size = 192879, upload-time = "2026-04-12T21:44:40.882Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a7/08/673a7bb05e5702dc787ddd3011195b509f9867927970da59052211929987/msgspec-0.21.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f60800e6299b798142dc40b0644da77ceac5ea0568be58228417eae14135c847", size = 226281, upload-time = "2026-04-12T21:44:42.181Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7d/45/86508cf57283e9070b3c447e3ab25b792a7a0855a3ea4e0c6d111ac34c97/msgspec-0.21.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5f8e9dfcd98419cf7568808470c4317a3fb30bef0e3715b568730a2b272a20d7", size = 229863, upload-time = "2026-04-12T21:44:43.442Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/62/e7c9367cd08d590559faacd711edbae36840342843e669440363f33c7d36/msgspec-0.21.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:92d89dfad13bd1ea640dc3e37e724ed380da1030b272bdf5ecafb983c3ad7c75", size = 230445, upload-time = "2026-04-12T21:44:44.806Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/42/b4/c0f54632103846b658a10930025f4de41c8724b5e4805a5f3b395586cb7e/msgspec-0.21.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:0d03867786e5d7ba25d666df4b11320c27170f4aeafcb8e3a8b0a50a4fb742ca", size = 231822, upload-time = "2026-04-12T21:44:46.343Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ea/1d/0d85cc79d0ccf5508e9c846cc66552a6a16bf92abd1dbd8362617f7b35cd/msgspec-0.21.1-cp314-cp314t-win_amd64.whl", hash = "sha256:740fbf1c9d59992ca3537d6fbe9ebbf9eaf726a65fbf31448e0ecbc710697a63", size = 206650, upload-time = "2026-04-12T21:44:47.601Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/90/91/56c5d560f20e6c20e9e4f55bd0e458f7f162aa689ee350346c04c48eac0b/msgspec-0.21.1-cp314-cp314t-win_arm64.whl", hash = "sha256:0d2cc73df6058d811a126ac3a8ad63a4dfa210c82f9cf5a004802eaf4712de90", size = 183149, upload-time = "2026-04-12T21:44:48.833Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -534,17 +559,30 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "8.3.5"
|
||||
version = "9.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "iniconfig" },
|
||||
{ name = "packaging" },
|
||||
{ name = "pluggy" },
|
||||
{ name = "pygments" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ae/3c/c9d525a414d506893f0cd8a8d0de7706446213181570cdbd766691164e40/pytest-8.3.5.tar.gz", hash = "sha256:f4efe70cc14e511565ac476b57c279e12a855b11f48f212af1080ef2263d3845", size = 1450891, upload-time = "2025-03-02T12:54:54.503Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/84/0e/b5858858d74958632c49b72cb25a3976ff9f632397626715be71c89d3971/pytest-9.1.0.tar.gz", hash = "sha256:41dd9148c08072446394cefd3d79701701335a9f4cae69ba92e39f6c7f5c061c", size = 1634181, upload-time = "2026-06-13T18:52:45.983Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/30/3d/64ad57c803f1fa1e963a7946b6e0fea4a70df53c1a7fed304586539c2bac/pytest-8.3.5-py3-none-any.whl", hash = "sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820", size = 343634, upload-time = "2025-03-02T12:54:52.069Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8b/5a/ba30a81239b909821b3153e303e7def45178bf353da4f72380e6c5e8793b/pytest-9.1.0-py3-none-any.whl", hash = "sha256:8ebb0e7888bdf2bdfc602ec51f8f62d50200af37356c74e503c79a94f5c81f32", size = 386453, upload-time = "2026-06-13T18:52:44.045Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-timeout"
|
||||
version = "2.4.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pytest" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ac/82/4c9ecabab13363e72d880f2fb504c5f750433b2b6f16e99f4ec21ada284c/pytest_timeout-2.4.0.tar.gz", hash = "sha256:7e68e90b01f9eff71332b25001f85c75495fc4e3a836701876183c4bcfd0540a", size = 17973, upload-time = "2025-05-05T19:44:34.99Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/fa/b6/3127540ecdf1464a00e5a01ee60a1b09175f6913f0644ac748494d9c4b21/pytest_timeout-2.4.0-py3-none-any.whl", hash = "sha256:c42667e5cdadb151aeb5b26d114aff6bdf5a907f176a007a30b940d3d865b5c2", size = 14382, upload-time = "2025-05-05T19:44:33.502Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -579,6 +617,54 @@ wheels = [
|
|||
{ url = "https://files.pythonhosted.org/packages/9e/6a/40fee331a52339926a92e17ae748827270b288a35ef4a15c9c8f2ec54715/ruff-0.14.14-py3-none-win_arm64.whl", hash = "sha256:56e6981a98b13a32236a72a8da421d7839221fa308b223b9283312312e5ac76c", size = 10920448, upload-time = "2026-01-22T22:30:15.417Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "setproctitle"
|
||||
version = "1.3.7"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/8d/48/49393a96a2eef1ab418b17475fb92b8fcfad83d099e678751b05472e69de/setproctitle-1.3.7.tar.gz", hash = "sha256:bc2bc917691c1537d5b9bca1468437176809c7e11e5694ca79a9ca12345dcb9e", size = 27002, upload-time = "2025-09-05T12:51:25.278Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/5d/2f/fcedcade3b307a391b6e17c774c6261a7166aed641aee00ed2aad96c63ce/setproctitle-1.3.7-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:c3736b2a423146b5e62230502e47e08e68282ff3b69bcfe08a322bee73407922", size = 18047, upload-time = "2025-09-05T12:49:50.271Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/ae/afc141ca9631350d0a80b8f287aac79a76f26b6af28fd8bf92dae70dc2c5/setproctitle-1.3.7-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3384e682b158d569e85a51cfbde2afd1ab57ecf93ea6651fe198d0ba451196ee", size = 13073, upload-time = "2025-09-05T12:49:51.46Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/87/ed/0a4f00315bc02510395b95eec3d4aa77c07192ee79f0baae77ea7b9603d8/setproctitle-1.3.7-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:0564a936ea687cd24dffcea35903e2a20962aa6ac20e61dd3a207652401492dd", size = 33284, upload-time = "2025-09-05T12:49:52.741Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fc/e4/adf3c4c0a2173cb7920dc9df710bcc67e9bcdbf377e243b7a962dc31a51a/setproctitle-1.3.7-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a5d1cb3f81531f0eb40e13246b679a1bdb58762b170303463cb06ecc296f26d0", size = 34104, upload-time = "2025-09-05T12:49:54.416Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/52/4f/6daf66394152756664257180439d37047aa9a1cfaa5e4f5ed35e93d1dc06/setproctitle-1.3.7-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a7d159e7345f343b44330cbba9194169b8590cb13dae940da47aa36a72aa9929", size = 35982, upload-time = "2025-09-05T12:49:56.295Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1b/62/f2c0595403cf915db031f346b0e3b2c0096050e90e0be658a64f44f4278a/setproctitle-1.3.7-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:0b5074649797fd07c72ca1f6bff0406f4a42e1194faac03ecaab765ce605866f", size = 33150, upload-time = "2025-09-05T12:49:58.025Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a0/29/10dd41cde849fb2f9b626c846b7ea30c99c81a18a5037a45cc4ba33c19a7/setproctitle-1.3.7-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:61e96febced3f61b766115381d97a21a6265a0f29188a791f6df7ed777aef698", size = 34463, upload-time = "2025-09-05T12:49:59.424Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/3c/cedd8eccfaf15fb73a2c20525b68c9477518917c9437737fa0fda91e378f/setproctitle-1.3.7-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:047138279f9463f06b858e579cc79580fbf7a04554d24e6bddf8fe5dddbe3d4c", size = 32848, upload-time = "2025-09-05T12:50:01.107Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/3e/0a0e27d1c9926fecccfd1f91796c244416c70bf6bca448d988638faea81d/setproctitle-1.3.7-cp313-cp313-win32.whl", hash = "sha256:7f47accafac7fe6535ba8ba9efd59df9d84a6214565108d0ebb1199119c9cbbd", size = 12544, upload-time = "2025-09-05T12:50:15.81Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/36/1b/6bf4cb7acbbd5c846ede1c3f4d6b4ee52744d402e43546826da065ff2ab7/setproctitle-1.3.7-cp313-cp313-win_amd64.whl", hash = "sha256:fe5ca35aeec6dc50cabab9bf2d12fbc9067eede7ff4fe92b8f5b99d92e21263f", size = 13235, upload-time = "2025-09-05T12:50:16.89Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e6/a4/d588d3497d4714750e3eaf269e9e8985449203d82b16b933c39bd3fc52a1/setproctitle-1.3.7-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:10e92915c4b3086b1586933a36faf4f92f903c5554f3c34102d18c7d3f5378e9", size = 18058, upload-time = "2025-09-05T12:50:02.501Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/05/77/7637f7682322a7244e07c373881c7e982567e2cb1dd2f31bd31481e45500/setproctitle-1.3.7-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:de879e9c2eab637f34b1a14c4da1e030c12658cdc69ee1b3e5be81b380163ce5", size = 13072, upload-time = "2025-09-05T12:50:03.601Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/52/09/f366eca0973cfbac1470068d1313fa3fe3de4a594683385204ec7f1c4101/setproctitle-1.3.7-cp313-cp313t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:c18246d88e227a5b16248687514f95642505000442165f4b7db354d39d0e4c29", size = 34490, upload-time = "2025-09-05T12:50:04.948Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/36/611fc2ed149fdea17c3677e1d0df30d8186eef9562acc248682b91312706/setproctitle-1.3.7-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7081f193dab22df2c36f9fc6d113f3793f83c27891af8fe30c64d89d9a37e152", size = 35267, upload-time = "2025-09-05T12:50:06.015Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/88/a4/64e77d0671446bd5a5554387b69e1efd915274686844bea733714c828813/setproctitle-1.3.7-cp313-cp313t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:9cc9b901ce129350637426a89cfd650066a4adc6899e47822e2478a74023ff7c", size = 37376, upload-time = "2025-09-05T12:50:07.484Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/89/bc/ad9c664fe524fb4a4b2d3663661a5c63453ce851736171e454fa2cdec35c/setproctitle-1.3.7-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:80e177eff2d1ec172188d0d7fd9694f8e43d3aab76a6f5f929bee7bf7894e98b", size = 33963, upload-time = "2025-09-05T12:50:09.056Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ab/01/a36de7caf2d90c4c28678da1466b47495cbbad43badb4e982d8db8167ed4/setproctitle-1.3.7-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:23e520776c445478a67ee71b2a3c1ffdafbe1f9f677239e03d7e2cc635954e18", size = 35550, upload-time = "2025-09-05T12:50:10.791Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dd/68/17e8aea0ed5ebc17fbf03ed2562bfab277c280e3625850c38d92a7b5fcd9/setproctitle-1.3.7-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:5fa1953126a3b9bd47049d58c51b9dac72e78ed120459bd3aceb1bacee72357c", size = 33727, upload-time = "2025-09-05T12:50:12.032Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b2/33/90a3bf43fe3a2242b4618aa799c672270250b5780667898f30663fd94993/setproctitle-1.3.7-cp313-cp313t-win32.whl", hash = "sha256:4a5e212bf438a4dbeece763f4962ad472c6008ff6702e230b4f16a037e2f6f29", size = 12549, upload-time = "2025-09-05T12:50:13.074Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0b/0e/50d1f07f3032e1f23d814ad6462bc0a138f369967c72494286b8a5228e40/setproctitle-1.3.7-cp313-cp313t-win_amd64.whl", hash = "sha256:cf2727b733e90b4f874bac53e3092aa0413fe1ea6d4f153f01207e6ce65034d9", size = 13243, upload-time = "2025-09-05T12:50:14.146Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/89/c7/43ac3a98414f91d1b86a276bc2f799ad0b4b010e08497a95750d5bc42803/setproctitle-1.3.7-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:80c36c6a87ff72eabf621d0c79b66f3bdd0ecc79e873c1e9f0651ee8bf215c63", size = 18052, upload-time = "2025-09-05T12:50:17.928Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cd/2c/dc258600a25e1a1f04948073826bebc55e18dbd99dc65a576277a82146fa/setproctitle-1.3.7-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:b53602371a52b91c80aaf578b5ada29d311d12b8a69c0c17fbc35b76a1fd4f2e", size = 13071, upload-time = "2025-09-05T12:50:19.061Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ab/26/8e3bb082992f19823d831f3d62a89409deb6092e72fc6940962983ffc94f/setproctitle-1.3.7-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:fcb966a6c57cf07cc9448321a08f3be6b11b7635be502669bc1d8745115d7e7f", size = 33180, upload-time = "2025-09-05T12:50:20.395Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f1/af/ae692a20276d1159dd0cf77b0bcf92cbb954b965655eb4a69672099bb214/setproctitle-1.3.7-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:46178672599b940368d769474fe13ecef1b587d58bb438ea72b9987f74c56ea5", size = 34043, upload-time = "2025-09-05T12:50:22.454Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/34/b2/6a092076324dd4dac1a6d38482bedebbff5cf34ef29f58585ec76e47bc9d/setproctitle-1.3.7-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7f9e9e3ff135cbcc3edd2f4cf29b139f4aca040d931573102742db70ff428c17", size = 35892, upload-time = "2025-09-05T12:50:23.937Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1c/1a/8836b9f28cee32859ac36c3df85aa03e1ff4598d23ea17ca2e96b5845a8f/setproctitle-1.3.7-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:14c7eba8d90c93b0e79c01f0bd92a37b61983c27d6d7d5a3b5defd599113d60e", size = 32898, upload-time = "2025-09-05T12:50:25.617Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ef/22/8fabdc24baf42defb599714799d8445fe3ae987ec425a26ec8e80ea38f8e/setproctitle-1.3.7-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:9e64e98077fb30b6cf98073d6c439cd91deb8ebbf8fc62d9dbf52bd38b0c6ac0", size = 34308, upload-time = "2025-09-05T12:50:26.827Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/15/1b/b9bee9de6c8cdcb3b3a6cb0b3e773afdb86bbbc1665a3bfa424a4294fda2/setproctitle-1.3.7-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:b91387cc0f02a00ac95dcd93f066242d3cca10ff9e6153de7ee07069c6f0f7c8", size = 32536, upload-time = "2025-09-05T12:50:28.5Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/37/0c/75e5f2685a5e3eda0b39a8b158d6d8895d6daf3ba86dec9e3ba021510272/setproctitle-1.3.7-cp314-cp314-win32.whl", hash = "sha256:52b054a61c99d1b72fba58b7f5486e04b20fefc6961cd76722b424c187f362ed", size = 12731, upload-time = "2025-09-05T12:50:43.955Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d2/ae/acddbce90d1361e1786e1fb421bc25baeb0c22ef244ee5d0176511769ec8/setproctitle-1.3.7-cp314-cp314-win_amd64.whl", hash = "sha256:5818e4080ac04da1851b3ec71e8a0f64e3748bf9849045180566d8b736702416", size = 13464, upload-time = "2025-09-05T12:50:45.057Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/01/6d/20886c8ff2e6d85e3cabadab6aab9bb90acaf1a5cfcb04d633f8d61b2626/setproctitle-1.3.7-cp314-cp314t-macosx_10_13_universal2.whl", hash = "sha256:6fc87caf9e323ac426910306c3e5d3205cd9f8dcac06d233fcafe9337f0928a3", size = 18062, upload-time = "2025-09-05T12:50:29.78Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9a/60/26dfc5f198715f1343b95c2f7a1c16ae9ffa45bd89ffd45a60ed258d24ea/setproctitle-1.3.7-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:6134c63853d87a4897ba7d5cc0e16abfa687f6c66fc09f262bb70d67718f2309", size = 13075, upload-time = "2025-09-05T12:50:31.604Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/21/9c/980b01f50d51345dd513047e3ba9e96468134b9181319093e61db1c47188/setproctitle-1.3.7-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:1403d2abfd32790b6369916e2313dffbe87d6b11dca5bbd898981bcde48e7a2b", size = 34744, upload-time = "2025-09-05T12:50:32.777Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/86/b4/82cd0c86e6d1c4538e1a7eb908c7517721513b801dff4ba3f98ef816a240/setproctitle-1.3.7-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e7c5bfe4228ea22373e3025965d1a4116097e555ee3436044f5c954a5e63ac45", size = 35589, upload-time = "2025-09-05T12:50:34.13Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8a/4f/9f6b2a7417fd45673037554021c888b31247f7594ff4bd2239918c5cd6d0/setproctitle-1.3.7-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:585edf25e54e21a94ccb0fe81ad32b9196b69ebc4fc25f81da81fb8a50cca9e4", size = 37698, upload-time = "2025-09-05T12:50:35.524Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/20/92/927b7d4744aac214d149c892cb5fa6dc6f49cfa040cb2b0a844acd63dcaf/setproctitle-1.3.7-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:96c38cdeef9036eb2724c2210e8d0b93224e709af68c435d46a4733a3675fee1", size = 34201, upload-time = "2025-09-05T12:50:36.697Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0a/0c/fd4901db5ba4b9d9013e62f61d9c18d52290497f956745cd3e91b0d80f90/setproctitle-1.3.7-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:45e3ef48350abb49cf937d0a8ba15e42cee1e5ae13ca41a77c66d1abc27a5070", size = 35801, upload-time = "2025-09-05T12:50:38.314Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e7/e3/54b496ac724e60e61cc3447f02690105901ca6d90da0377dffe49ff99fc7/setproctitle-1.3.7-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:1fae595d032b30dab4d659bece20debd202229fce12b55abab978b7f30783d73", size = 33958, upload-time = "2025-09-05T12:50:39.841Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ea/a8/c84bb045ebf8c6fdc7f7532319e86f8380d14bbd3084e6348df56bdfe6fd/setproctitle-1.3.7-cp314-cp314t-win32.whl", hash = "sha256:02432f26f5d1329ab22279ff863c83589894977063f59e6c4b4845804a08f8c2", size = 12745, upload-time = "2025-09-05T12:50:41.377Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/08/b6/3a5a4f9952972791a9114ac01dfc123f0df79903577a3e0a7a404a695586/setproctitle-1.3.7-cp314-cp314t-win_amd64.whl", hash = "sha256:cbc388e3d86da1f766d8fc2e12682e446064c01cea9f88a88647cfe7c011de6a", size = 13469, upload-time = "2025-09-05T12:50:42.67Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
version = "1.17.0"
|
||||
|
|
@ -633,12 +719,12 @@ version = "0.1.0a6.dev0"
|
|||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "bidict" },
|
||||
{ name = "cffi" },
|
||||
{ name = "colorlog" },
|
||||
{ name = "msgspec" },
|
||||
{ name = "multiaddr" },
|
||||
{ name = "pdbp" },
|
||||
{ name = "platformdirs" },
|
||||
{ name = "setproctitle" },
|
||||
{ name = "tricycle" },
|
||||
{ name = "trio" },
|
||||
{ name = "wrapt" },
|
||||
|
|
@ -646,21 +732,24 @@ dependencies = [
|
|||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "greenback" },
|
||||
{ name = "greenback", marker = "python_full_version < '3.14'" },
|
||||
{ name = "pexpect" },
|
||||
{ name = "prompt-toolkit" },
|
||||
{ name = "psutil" },
|
||||
{ name = "pyperclip" },
|
||||
{ name = "pytest" },
|
||||
{ name = "pytest-timeout" },
|
||||
{ name = "stackscope" },
|
||||
{ name = "typing-extensions" },
|
||||
{ name = "xonsh" },
|
||||
]
|
||||
devx = [
|
||||
{ name = "greenback" },
|
||||
{ name = "stackscope" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
eventfd = [
|
||||
{ name = "cffi", marker = "python_full_version < '3.14'" },
|
||||
]
|
||||
lint = [
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
|
@ -670,20 +759,28 @@ repl = [
|
|||
{ name = "pyperclip" },
|
||||
{ name = "xonsh" },
|
||||
]
|
||||
subints = [
|
||||
{ name = "msgspec", marker = "python_full_version >= '3.14'" },
|
||||
]
|
||||
sync-pause = [
|
||||
{ name = "greenback", marker = "python_full_version < '3.14'" },
|
||||
]
|
||||
testing = [
|
||||
{ name = "pexpect" },
|
||||
{ name = "psutil" },
|
||||
{ name = "pytest" },
|
||||
{ name = "pytest-timeout" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "bidict", specifier = ">=0.23.1" },
|
||||
{ name = "cffi", specifier = ">=1.17.1" },
|
||||
{ name = "colorlog", specifier = ">=6.8.2,<7" },
|
||||
{ name = "msgspec", specifier = ">=0.21.0" },
|
||||
{ name = "msgspec", specifier = ">=0.20.0" },
|
||||
{ name = "multiaddr", specifier = ">=0.2.0" },
|
||||
{ name = "pdbp", specifier = ">=1.8.2,<2" },
|
||||
{ name = "platformdirs", specifier = ">=4.4.0" },
|
||||
{ name = "setproctitle", specifier = ">=1.3,<2" },
|
||||
{ name = "tricycle", specifier = ">=0.4.1,<0.5" },
|
||||
{ name = "trio", specifier = ">0.27" },
|
||||
{ name = "wrapt", specifier = ">=1.16.0,<2" },
|
||||
|
|
@ -691,31 +788,36 @@ requires-dist = [
|
|||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [
|
||||
{ name = "greenback", specifier = ">=1.2.1,<2" },
|
||||
{ name = "greenback", marker = "python_full_version == '3.13.*'", specifier = ">=1.2.1,<2" },
|
||||
{ name = "pexpect", specifier = ">=4.9.0,<5" },
|
||||
{ name = "prompt-toolkit", specifier = ">=3.0.50" },
|
||||
{ name = "psutil", specifier = ">=7.0.0" },
|
||||
{ name = "pyperclip", specifier = ">=1.9.0" },
|
||||
{ name = "pytest", specifier = ">=8.3.5" },
|
||||
{ name = "pytest", specifier = ">=9.0.3" },
|
||||
{ name = "pytest-timeout", specifier = ">=2.3" },
|
||||
{ name = "stackscope", specifier = ">=0.2.2,<0.3" },
|
||||
{ name = "typing-extensions", specifier = ">=4.14.1" },
|
||||
{ name = "xonsh", specifier = ">=0.22.2" },
|
||||
{ name = "xonsh", specifier = ">=0.23.8" },
|
||||
]
|
||||
devx = [
|
||||
{ name = "greenback", specifier = ">=1.2.1,<2" },
|
||||
{ name = "stackscope", specifier = ">=0.2.2,<0.3" },
|
||||
{ name = "typing-extensions", specifier = ">=4.14.1" },
|
||||
]
|
||||
eventfd = [{ name = "cffi", marker = "python_full_version == '3.13.*'", specifier = ">=1.17.1" }]
|
||||
lint = [{ name = "ruff", specifier = ">=0.9.6" }]
|
||||
repl = [
|
||||
{ name = "prompt-toolkit", specifier = ">=3.0.50" },
|
||||
{ name = "psutil", specifier = ">=7.0.0" },
|
||||
{ name = "pyperclip", specifier = ">=1.9.0" },
|
||||
{ name = "xonsh", specifier = ">=0.22.2" },
|
||||
{ name = "xonsh", specifier = ">=0.23.8" },
|
||||
]
|
||||
subints = [{ name = "msgspec", marker = "python_full_version >= '3.14'", specifier = ">=0.21.0" }]
|
||||
sync-pause = [{ name = "greenback", marker = "python_full_version == '3.13.*'", specifier = ">=1.2.1,<2" }]
|
||||
testing = [
|
||||
{ name = "pexpect", specifier = ">=4.9.0,<5" },
|
||||
{ name = "pytest", specifier = ">=8.3.5" },
|
||||
{ name = "psutil", specifier = ">=7.0.0" },
|
||||
{ name = "pytest", specifier = ">=9.0.3" },
|
||||
{ name = "pytest-timeout", specifier = ">=2.3" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -794,17 +896,6 @@ version = "1.17.2"
|
|||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c3/fc/e91cc220803d7bc4db93fb02facd8461c37364151b8494762cc88b0fbcef/wrapt-1.17.2.tar.gz", hash = "sha256:41388e9d4d1522446fe79d3213196bd9e3b301a336965b9e27ca2788ebd122f3", size = 55531, upload-time = "2025-01-14T10:35:45.465Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a1/bd/ab55f849fd1f9a58ed7ea47f5559ff09741b25f00c191231f9f059c83949/wrapt-1.17.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:d5e2439eecc762cd85e7bd37161d4714aa03a33c5ba884e26c81559817ca0925", size = 53799, upload-time = "2025-01-14T10:33:57.4Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/53/18/75ddc64c3f63988f5a1d7e10fb204ffe5762bc663f8023f18ecaf31a332e/wrapt-1.17.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:3fc7cb4c1c744f8c05cd5f9438a3caa6ab94ce8344e952d7c45a8ed59dd88392", size = 38821, upload-time = "2025-01-14T10:33:59.334Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/48/2a/97928387d6ed1c1ebbfd4efc4133a0633546bec8481a2dd5ec961313a1c7/wrapt-1.17.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8fdbdb757d5390f7c675e558fd3186d590973244fab0c5fe63d373ade3e99d40", size = 38919, upload-time = "2025-01-14T10:34:04.093Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/73/54/3bfe5a1febbbccb7a2f77de47b989c0b85ed3a6a41614b104204a788c20e/wrapt-1.17.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5bb1d0dbf99411f3d871deb6faa9aabb9d4e744d67dcaaa05399af89d847a91d", size = 88721, upload-time = "2025-01-14T10:34:07.163Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/25/cb/7262bc1b0300b4b64af50c2720ef958c2c1917525238d661c3e9a2b71b7b/wrapt-1.17.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d18a4865f46b8579d44e4fe1e2bcbc6472ad83d98e22a26c963d46e4c125ef0b", size = 80899, upload-time = "2025-01-14T10:34:09.82Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2a/5a/04cde32b07a7431d4ed0553a76fdb7a61270e78c5fd5a603e190ac389f14/wrapt-1.17.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc570b5f14a79734437cb7b0500376b6b791153314986074486e0b0fa8d71d98", size = 89222, upload-time = "2025-01-14T10:34:11.258Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/09/28/2e45a4f4771fcfb109e244d5dbe54259e970362a311b67a965555ba65026/wrapt-1.17.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6d9187b01bebc3875bac9b087948a2bccefe464a7d8f627cf6e48b1bbae30f82", size = 86707, upload-time = "2025-01-14T10:34:12.49Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c6/d2/dcb56bf5f32fcd4bd9aacc77b50a539abdd5b6536872413fd3f428b21bed/wrapt-1.17.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:9e8659775f1adf02eb1e6f109751268e493c73716ca5761f8acb695e52a756ae", size = 79685, upload-time = "2025-01-14T10:34:15.043Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/80/4e/eb8b353e36711347893f502ce91c770b0b0929f8f0bed2670a6856e667a9/wrapt-1.17.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e8b2816ebef96d83657b56306152a93909a83f23994f4b30ad4573b00bd11bb9", size = 87567, upload-time = "2025-01-14T10:34:16.563Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/17/27/4fe749a54e7fae6e7146f1c7d914d28ef599dacd4416566c055564080fe2/wrapt-1.17.2-cp312-cp312-win32.whl", hash = "sha256:468090021f391fe0056ad3e807e3d9034e0fd01adcd3bdfba977b6fdf4213ea9", size = 36672, upload-time = "2025-01-14T10:34:17.727Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/15/06/1dbf478ea45c03e78a6a8c4be4fdc3c3bddea5c8de8a93bc971415e47f0f/wrapt-1.17.2-cp312-cp312-win_amd64.whl", hash = "sha256:ec89ed91f2fa8e3f52ae53cd3cf640d6feff92ba90d62236a81e4e563ac0e991", size = 38865, upload-time = "2025-01-14T10:34:19.577Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ce/b9/0ffd557a92f3b11d4c5d5e0c5e4ad057bd9eb8586615cdaf901409920b14/wrapt-1.17.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:6ed6ffac43aecfe6d86ec5b74b06a5be33d5bb9243d055141e8cabb12aa08125", size = 53800, upload-time = "2025-01-14T10:34:21.571Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c0/ef/8be90a0b7e73c32e550c73cfb2fa09db62234227ece47b0e80a05073b375/wrapt-1.17.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:35621ae4c00e056adb0009f8e86e28eb4a41a4bfa8f9bfa9fca7d343fe94f998", size = 38824, upload-time = "2025-01-14T10:34:22.999Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/36/89/0aae34c10fe524cce30fe5fc433210376bce94cf74d05b0d68344c8ba46e/wrapt-1.17.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a604bf7a053f8362d27eb9fefd2097f82600b856d5abe996d623babd067b1ab5", size = 38920, upload-time = "2025-01-14T10:34:25.386Z" },
|
||||
|
|
@ -832,13 +923,14 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "xonsh"
|
||||
version = "0.22.4"
|
||||
version = "0.23.8"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/48/df/1fc9ed62b3d7c14612e1713e9eb7bd41d54f6ad1028a8fbb6b7cddebc345/xonsh-0.22.4.tar.gz", hash = "sha256:6be346563fec2db75778ba5d2caee155525e634e99d9cc8cc347626025c0b3fa", size = 826665, upload-time = "2026-02-17T07:53:39.424Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/8b/77/0c4c39ad866d4ea1ef553f325d16e804d1bf1eeecc591f0e81b057aa37db/xonsh-0.23.8.tar.gz", hash = "sha256:541bb976c93a81571792644403bae8737145023da5f48d4c493909ab5c04ba0f", size = 1172271, upload-time = "2026-05-30T04:47:22.53Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/2e/00/7cbc0c1fb64365a0a317c54ce3a151c9644eea5a509d9cbaae61c9fd1426/xonsh-0.22.4-py311-none-any.whl", hash = "sha256:38b29b29fa85aa756462d9d9bbcaa1d85478c2108da3de6cc590a69a4bcd1a01", size = 654375, upload-time = "2026-02-17T07:53:37.702Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2e/c2/3dd498dc28d8f89cdd52e39950c5e591499ae423f61694c0bb4d03ed1d82/xonsh-0.22.4-py312-none-any.whl", hash = "sha256:4e538fac9f4c3d866ddbdeca068f0c0515469c997ed58d3bfee963878c6df5a5", size = 654300, upload-time = "2026-02-17T07:53:35.813Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/82/7d/1f9c7147518e9f03f6ce081b5bfc4f1aceb6ec5caba849024d005e41d3be/xonsh-0.22.4-py313-none-any.whl", hash = "sha256:cc5fabf0ad0c56a2a11bed1e6a43c4ec6416a5b30f24f126b8e768547c3793e2", size = 654818, upload-time = "2026-02-17T07:53:33.477Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ca/4a/2aab8300ad218dfc7678c34d5f703f09df5681fecc6e66d48c951ef58049/xonsh-0.23.8-py311-none-any.whl", hash = "sha256:4bab3e405643df2cc78ec2cac13241471841796fe710386d2179666aae8a5f9c", size = 799846, upload-time = "2026-05-30T04:47:21.211Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/87/ec/aa66ef6046f90769dd8fcb3ddca9d00282d12e3d73645abbf12f190f17cf/xonsh-0.23.8-py312-none-any.whl", hash = "sha256:c7d0f0fba0cafe0bd75bf202820aeffc74b52943fa27d98d3b4346793f6ba493", size = 799868, upload-time = "2026-05-30T04:47:19.158Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/12/fe/2d757d82b57332f1c6cd3f8c168fbcf060a275895a763542255ae1c53d75/xonsh-0.23.8-py313-none-any.whl", hash = "sha256:1b7335522a6ecd63f0d84151977a7a9050874d3ecec00cf79919d0770bebb1b4", size = 800388, upload-time = "2026-05-30T04:47:18.47Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/80/96/567bb3131655ff73c821e8a030c53707ced6c8840330a859f67bbaefbd16/xonsh-0.23.8-py314-none-any.whl", hash = "sha256:2a411fc47958c6107b3e13372655d18c52be98368e2159a1910cfde77124b3b1", size = 800352, upload-time = "2026-05-30T04:47:14.812Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,586 @@
|
|||
"""
|
||||
`xontrib_tractor_diag`: pytest/tractor diagnostic aliases.
|
||||
|
||||
All aliases live under the `acli.` namespace so xonsh's
|
||||
prefix-completion treats them as a sub-cmd group — type
|
||||
`acli.<TAB>` to see the full set.
|
||||
|
||||
Provides:
|
||||
- `acli.ptree <pid|pgrep-pat>` psutil-backed proc tree,
|
||||
live + zombies split.
|
||||
- `acli.hung_dump <pid|pat> [...]` kernel `wchan`/`stack` +
|
||||
`py-spy dump` (incl `--locals`)
|
||||
for each pid in tree.
|
||||
- `acli.bindspace_scan [<name>|<dir>]` find orphaned tractor UDS
|
||||
sock files (no live owner pid).
|
||||
bare name -> `$XDG_RUNTIME_DIR/<name>`
|
||||
(e.g. `piker`, `tractor`);
|
||||
path -> use as-is.
|
||||
default: `$XDG_RUNTIME_DIR/tractor`.
|
||||
- `acli.dump_all <pid> [--out-dir] full snapshot bundle —
|
||||
[--label]` ptree + hung_dump + bindspace
|
||||
written to a timestamped dir
|
||||
for sharing / AI introspection.
|
||||
- `acli.reap [opts]` SC-polite zombie-subactor
|
||||
reaper + optional `/dev/shm/`
|
||||
+ UDS sock-file sweeps.
|
||||
alias for `scripts/tractor-reap`.
|
||||
- `acli.watch [-n SEC] <alias-name> run a callable alias in
|
||||
[alias-args]` an alt-screen loop with
|
||||
flicker-free repaint
|
||||
(cursor-home + per-line
|
||||
EL + post-draw erase-down).
|
||||
|
||||
Loading from repo root:
|
||||
xontrib load -p ./xontrib tractor_diag
|
||||
|
||||
Or source directly:
|
||||
source ./xontrib/tractor_diag.xsh
|
||||
|
||||
Pipe-to-paste idiom (xonsh):
|
||||
acli.hung_dump pytest |t /tmp/hung.log
|
||||
|
||||
The diagnostic core lives in `tractor._testing.trace` so it
|
||||
can also be invoked from inside pytest tests (e.g. via
|
||||
`fail_after_w_trace` / `afk_alarm_w_trace` capture-on-hang
|
||||
helpers) — these aliases are just thin terminal wrappers.
|
||||
|
||||
Requires `psutil` for full functionality (`ptree` and the
|
||||
`hung_dump` tree-walk). Falls back to `pgrep -P` recursion if
|
||||
missing.
|
||||
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import time
|
||||
from typing import (
|
||||
Callable,
|
||||
)
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from tractor._testing.trace import (
|
||||
dump_all as _dump_all,
|
||||
dump_hung_state,
|
||||
dump_proc_tree,
|
||||
resolve_pids,
|
||||
scan_bindspace,
|
||||
)
|
||||
|
||||
@aliases.unthreadable
|
||||
def watch(
|
||||
args: list[str],
|
||||
) -> int:
|
||||
'''
|
||||
A per-term optimized `watch`-like alias for xonsh
|
||||
that runs an arbitrary callable alias in a loop
|
||||
inside the alt-screen buffer. Ctrl-C returns to a
|
||||
pristine shell, SIGWINCH triggers a full redraw,
|
||||
and the per-frame draw uses cursor-home + per-line
|
||||
EL + post-draw erase-down so the loop is flicker-
|
||||
free even when individual lines shrink or grow
|
||||
between frames.
|
||||
|
||||
usage: acli.watch [-n SEC] <alias-name>
|
||||
[alias-args]...
|
||||
|
||||
Examples:
|
||||
|
||||
acli.watch acli.ptree pytest
|
||||
acli.watch -n 1.0 acli.bindspace_scan piker
|
||||
acli.watch acli.hung_dump pytest
|
||||
|
||||
Only callable aliases (Python functions registered
|
||||
in `aliases`) are supported. Subprocess-style
|
||||
aliases raise an error — wrap them in a thin
|
||||
callable if you need watching.
|
||||
|
||||
Output capture: the watched alias's stdout is
|
||||
redirected into a `StringIO` per frame so we can
|
||||
post-process it (insert `\033[K` before each `\n`).
|
||||
Aliases that write directly to `sys.stdout.buffer`
|
||||
or `os.write(1, ...)` bypass capture; for those the
|
||||
EL-fix won't apply but the loop still functions.
|
||||
|
||||
'''
|
||||
import argparse, io
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='acli.watch',
|
||||
description=watch.__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'-n', '--interval',
|
||||
type=float,
|
||||
default=0.3,
|
||||
help='poll interval in seconds (default: 0.3)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'alias',
|
||||
help='name of a registered xonsh callable alias',
|
||||
)
|
||||
parser.add_argument(
|
||||
'alias_args',
|
||||
nargs=argparse.REMAINDER,
|
||||
help='args forwarded to the watched alias',
|
||||
)
|
||||
|
||||
try:
|
||||
ns = parser.parse_args(args)
|
||||
except SystemExit as se:
|
||||
return int(se.code) if se.code is not None else 0
|
||||
|
||||
raw = aliases.get(ns.alias)
|
||||
if raw is None:
|
||||
print(
|
||||
f'[acli.watch] no such alias: {ns.alias!r}'
|
||||
)
|
||||
return 1
|
||||
|
||||
# xonsh stores callable aliases as a bare callable
|
||||
# OR wraps them in `[fn, *preset_args]` (depending
|
||||
# on registration path / version). Unwrap both.
|
||||
fn: Callable|None = None
|
||||
preset_args: list = []
|
||||
if callable(raw):
|
||||
fn = raw
|
||||
elif (
|
||||
isinstance(raw, list)
|
||||
and raw
|
||||
and callable(raw[0])
|
||||
):
|
||||
fn = raw[0]
|
||||
preset_args = list(raw[1:])
|
||||
|
||||
if fn is None:
|
||||
kind: str = type(raw).__name__
|
||||
print(
|
||||
f'[acli.watch] alias {ns.alias!r} is not a '
|
||||
f'callable alias (got {kind}); '
|
||||
f'subprocess-style aliases not supported'
|
||||
)
|
||||
return 1
|
||||
|
||||
_FD: int = sys.stdout.fileno()
|
||||
need_full_clear: bool = False
|
||||
|
||||
def _on_winch(signum, frame):
|
||||
nonlocal need_full_clear
|
||||
need_full_clear = True
|
||||
|
||||
prev_winch = signal.signal(
|
||||
signal.SIGWINCH,
|
||||
_on_winch,
|
||||
)
|
||||
prev_sigint = signal.signal(
|
||||
signal.SIGINT,
|
||||
signal.default_int_handler,
|
||||
)
|
||||
|
||||
os.write(_FD, b'\033[?1049h\033[?25l')
|
||||
try:
|
||||
while True:
|
||||
buf = io.StringIO()
|
||||
with redirect_stdout(buf):
|
||||
fn(preset_args + ns.alias_args)
|
||||
|
||||
if need_full_clear:
|
||||
os.write(_FD, b'\033[H\033[2J')
|
||||
need_full_clear = False
|
||||
else:
|
||||
os.write(_FD, b'\033[H')
|
||||
|
||||
# `\033[K` (EL) before each newline erases
|
||||
# any stale tail chars left by a longer
|
||||
# prior-frame version of the same line.
|
||||
text: str = buf.getvalue()
|
||||
painted: bytes = (
|
||||
text.replace('\n', '\033[K\n').encode()
|
||||
)
|
||||
os.write(_FD, painted)
|
||||
os.write(_FD, b'\033[J')
|
||||
time.sleep(ns.interval)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
os.write(_FD, b'\033[?25h\033[?1049l')
|
||||
signal.signal(signal.SIGWINCH, prev_winch)
|
||||
signal.signal(signal.SIGINT, prev_sigint)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
# --- ptree ----------------------------------------------------
|
||||
|
||||
def _ptree(
|
||||
args: list[str],
|
||||
):
|
||||
'''
|
||||
psutil-backed proc tree; per-proc classification into
|
||||
severity-ordered buckets so leaked / defunct procs
|
||||
don't hide in the noise of normal `live` rows.
|
||||
|
||||
usage: acli.ptree [--tree|-t] <pid|pgrep-pattern> [...]
|
||||
|
||||
See `tractor._testing.trace.dump_proc_tree()` for the
|
||||
bucket semantics + classification details.
|
||||
|
||||
To watch this live with flicker-free repaint
|
||||
(alt-screen, per-line EL, SIGWINCH-aware):
|
||||
|
||||
.. code-block:: xonsh
|
||||
|
||||
acli.watch acli.ptree pytest
|
||||
|
||||
'''
|
||||
flag_tree: bool = False
|
||||
pos_args: list = []
|
||||
for a in args:
|
||||
if a in ('--tree', '-t'):
|
||||
flag_tree = True
|
||||
else:
|
||||
pos_args.append(a)
|
||||
|
||||
if not pos_args:
|
||||
print('usage: acli.ptree [--tree|-t] <pid|pgrep-pattern> [...]')
|
||||
return 1
|
||||
|
||||
roots: list = []
|
||||
for a in pos_args:
|
||||
roots.extend(resolve_pids(a))
|
||||
roots = sorted(set(roots))
|
||||
if not roots:
|
||||
print(f'(no procs match: {pos_args})')
|
||||
return 1
|
||||
|
||||
print(dump_proc_tree(roots, flag_tree=flag_tree), end='')
|
||||
|
||||
|
||||
# --- hung-dump -----------------------------------------------
|
||||
|
||||
def _hung_dump(args):
|
||||
'''
|
||||
kernel + python state for a hung pytest/tractor tree.
|
||||
walks all descendants of each `<pid|pgrep-pat>` arg.
|
||||
|
||||
usage: acli.hung_dump <pid|pgrep-pattern> [...]
|
||||
|
||||
note: `/proc/<pid>/stack` and `py-spy dump` typically
|
||||
require CAP_SYS_PTRACE — invoked via `sudo -n`. If sudo
|
||||
isn't cached this alias prompts (via `sudo -v`); for the
|
||||
non-interactive equivalent see
|
||||
`tractor._testing.trace.dump_hung_state(allow_sudo_prompt=False)`.
|
||||
|
||||
'''
|
||||
if not args:
|
||||
print('usage: acli.hung_dump <pid|pgrep-pattern> [...]')
|
||||
return 1
|
||||
|
||||
roots: list = []
|
||||
for a in args:
|
||||
roots.extend(resolve_pids(a))
|
||||
roots = sorted(set(roots))
|
||||
if not roots:
|
||||
print(f'(no procs match: {args})')
|
||||
return 1
|
||||
|
||||
print(
|
||||
dump_hung_state(roots, allow_sudo_prompt=True),
|
||||
end='',
|
||||
)
|
||||
|
||||
|
||||
# --- bindspace-scan ------------------------------------------
|
||||
|
||||
def _bindspace_scan(args):
|
||||
'''
|
||||
Scan a tractor UDS bindspace dir for orphan sock files.
|
||||
|
||||
usage: acli.bindspace_scan [<name>|<dir>]
|
||||
|
||||
See `tractor._testing.trace.scan_bindspace()` for full arg
|
||||
semantics + output-bucket details.
|
||||
|
||||
'''
|
||||
arg: str | None = args[0] if args else None
|
||||
print(scan_bindspace(arg), end='')
|
||||
|
||||
|
||||
# --- dump-all (snapshot bundle) ------------------------------
|
||||
|
||||
def _dump_all_alias(args):
|
||||
'''
|
||||
Capture a full diag snapshot bundle for a hung proc-tree
|
||||
into a timestamped directory for offline / AI inspection.
|
||||
|
||||
usage: acli.dump_all <pid|pgrep-pat>
|
||||
[--label <label>]
|
||||
[--out-dir <path>]
|
||||
|
||||
Writes:
|
||||
<out_dir>/<label>__<ts>/{trace.txt, bindspace.txt, meta.json}
|
||||
|
||||
Defaults:
|
||||
--label = `manual`
|
||||
--out-dir = `$XDG_CACHE_HOME/tractor/hung-dumps/`
|
||||
(fallback `~/.cache/tractor/hung-dumps/`)
|
||||
|
||||
'''
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='acli.dump_all',
|
||||
description=_dump_all_alias.__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'target',
|
||||
help='pid or pgrep -f pattern',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--label', '-l',
|
||||
default='manual',
|
||||
help='snapshot dir label prefix (default: `manual`)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--out-dir', '-o',
|
||||
type=Path,
|
||||
default=None,
|
||||
help='snapshot root dir (default: '
|
||||
'$XDG_CACHE_HOME/tractor/hung-dumps/)',
|
||||
)
|
||||
try:
|
||||
ns = parser.parse_args(args)
|
||||
except SystemExit as se:
|
||||
return int(se.code) if se.code is not None else 0
|
||||
|
||||
pids: list = resolve_pids(ns.target)
|
||||
if not pids:
|
||||
print(f'(no procs match: {ns.target})')
|
||||
return 1
|
||||
|
||||
# snapshot scoped to ONE root — pick the first matched
|
||||
# pid. Multi-root snapshots can be done by invoking
|
||||
# `acli.dump_all <pid>` per root.
|
||||
root_pid: int = pids[0]
|
||||
if len(pids) > 1:
|
||||
print(
|
||||
f'[acli.dump_all] {len(pids)} pids matched '
|
||||
f'{ns.target!r}; snapshotting tree from {root_pid} '
|
||||
f'(re-run per-pid for others: {pids[1:]})'
|
||||
)
|
||||
|
||||
dump_dir = _dump_all(
|
||||
root_pid,
|
||||
out_dir=ns.out_dir,
|
||||
label=ns.label,
|
||||
allow_sudo_prompt=True, # CLI: ok to prompt
|
||||
)
|
||||
print(f'[acli.dump_all] snapshot written to: {dump_dir}')
|
||||
|
||||
|
||||
# --- acli.reap ------------------------------------------------
|
||||
|
||||
def _tractor_reap(args):
|
||||
'''
|
||||
SC-polite zombie-subactor reaper + optional `/dev/shm/`
|
||||
orphan-segment sweep + optional UDS sock-file sweep.
|
||||
|
||||
usage: acli.reap [-h] [--parent PID] [--grace SEC]
|
||||
[--dry-run] [--shm | --shm-only]
|
||||
[--uds | --uds-only]
|
||||
|
||||
phases (run in order when enabled):
|
||||
|
||||
1. process reap — finds tractor subactor procs left
|
||||
alive after a `pytest`/app run that failed to fully
|
||||
cancel its tree. Default = orphan-mode (PPid==1
|
||||
init-reparented procs whose cwd matches repo root
|
||||
AND cmdline contains `python`). With `--parent`,
|
||||
scopes to descendants of a specific live PID.
|
||||
SIGINT first, then SIGKILL after `--grace` (default
|
||||
3.0s).
|
||||
2. shm sweep (`--shm`/`--shm-only`) — unlinks
|
||||
`/dev/shm/<file>` entries owned by the current uid
|
||||
that no live process has open. Needed because
|
||||
`tractor` disables `mp.resource_tracker`.
|
||||
3. UDS sweep (`--uds`/`--uds-only`) — unlinks
|
||||
`${XDG_RUNTIME_DIR}/tractor/<name>@<pid>.sock`
|
||||
files whose binder pid is dead (or the `1616`
|
||||
registry sentinel). See issue #452.
|
||||
|
||||
Mirrors `scripts/tractor-reap` (use `-n`/`--dry-run`
|
||||
first to see what would be touched).
|
||||
|
||||
'''
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='acli.reap',
|
||||
description=_tractor_reap.__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--parent', '-p',
|
||||
type=int,
|
||||
default=None,
|
||||
help='descendant-mode: reap procs with PPid==<pid>',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--grace', '-g',
|
||||
type=float,
|
||||
default=3.0,
|
||||
help='SIGINT grace window in seconds (default 3.0)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dry-run', '-n',
|
||||
action='store_true',
|
||||
help='list matched pids/paths but do not signal/unlink',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--shm',
|
||||
action='store_true',
|
||||
help='also unlink orphaned /dev/shm segments',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--shm-only',
|
||||
action='store_true',
|
||||
help='skip process reap; only do the shm sweep',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--uds',
|
||||
action='store_true',
|
||||
help='also unlink orphaned UDS sock-files',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--uds-only',
|
||||
action='store_true',
|
||||
help='skip process reap + shm; only do the UDS sweep',
|
||||
)
|
||||
|
||||
try:
|
||||
ns = parser.parse_args(args)
|
||||
except SystemExit as se:
|
||||
# `argparse` raises SystemExit on `-h`/bad-args; let
|
||||
# xonsh treat it as a normal alias return code.
|
||||
return int(se.code) if se.code is not None else 0
|
||||
|
||||
skip_proc_reap: bool = (
|
||||
ns.shm_only
|
||||
or
|
||||
ns.uds_only
|
||||
)
|
||||
|
||||
# `tractor` is assumed to be importable in the xonsh env
|
||||
# this xontrib was sourced into (a venv with the package
|
||||
# installed). The standalone `scripts/tractor-reap` does
|
||||
# `git rev-parse --show-toplevel` + `sys.path.insert` for
|
||||
# cold-shell usability — that overhead is unnecessary
|
||||
# here since we're already inside the project's venv.
|
||||
from tractor._testing._reap import (
|
||||
find_descendants,
|
||||
find_orphans,
|
||||
find_orphaned_shm,
|
||||
find_orphaned_uds,
|
||||
reap,
|
||||
reap_shm,
|
||||
reap_uds,
|
||||
_TRACTOR_PROC_CMDLINE_MARKERS,
|
||||
)
|
||||
|
||||
rc: int = 0
|
||||
|
||||
# phase 1: process reap (skipped under `--*-only`)
|
||||
if not skip_proc_reap:
|
||||
if ns.parent is not None:
|
||||
pids: list = find_descendants(ns.parent)
|
||||
mode: str = f'descendants of PPid={ns.parent}'
|
||||
else:
|
||||
pids = find_orphans()
|
||||
mode = (
|
||||
f'orphans (PPid==1, intrinsic '
|
||||
f'cmdline/comm match — {_TRACTOR_PROC_CMDLINE_MARKERS}'
|
||||
)
|
||||
|
||||
if not pids:
|
||||
print(f'[acli.reap] no {mode} to reap')
|
||||
elif ns.dry_run:
|
||||
print(
|
||||
f'[acli.reap] dry-run — {mode}:\n {pids}'
|
||||
)
|
||||
else:
|
||||
_, survivors = reap(pids, grace=ns.grace)
|
||||
if survivors:
|
||||
rc = 1
|
||||
|
||||
# phase 2: shm sweep (opt-in)
|
||||
if ns.shm or ns.shm_only:
|
||||
leaked: list = find_orphaned_shm()
|
||||
if not leaked:
|
||||
print(
|
||||
'[acli.reap] no orphaned /dev/shm '
|
||||
'segments to sweep'
|
||||
)
|
||||
elif ns.dry_run:
|
||||
print(
|
||||
f'[acli.reap] dry-run — {len(leaked)} '
|
||||
f'orphaned shm segment(s):\n {leaked}'
|
||||
)
|
||||
else:
|
||||
_, errors = reap_shm(leaked)
|
||||
if errors:
|
||||
rc = 1
|
||||
|
||||
# phase 3: UDS sweep (opt-in)
|
||||
if ns.uds or ns.uds_only:
|
||||
leaked_uds: list = find_orphaned_uds()
|
||||
if not leaked_uds:
|
||||
print(
|
||||
'[acli.reap] no orphaned UDS sock-files '
|
||||
'to sweep'
|
||||
)
|
||||
elif ns.dry_run:
|
||||
print(
|
||||
f'[acli.reap] dry-run — {len(leaked_uds)} '
|
||||
f'orphaned UDS sock-file(s):\n {leaked_uds}'
|
||||
)
|
||||
else:
|
||||
_, errors = reap_uds(leaked_uds)
|
||||
if errors:
|
||||
rc = 1
|
||||
|
||||
return rc
|
||||
|
||||
|
||||
# --- registration ---------------------------------------------
|
||||
|
||||
# all aliases under the `acli.` namespace so xonsh's prefix-
|
||||
# completion makes them feel like a sub-cmd group: type
|
||||
# `acli.<TAB>` and the full set is suggested. no parent
|
||||
# `acli` cmd exists — the dot is purely a naming convention.
|
||||
_TCLI_ALIASES: dict = {
|
||||
'acli.ptree': _ptree,
|
||||
'acli.hung_dump': _hung_dump,
|
||||
'acli.bindspace_scan': _bindspace_scan,
|
||||
'acli.dump_all': _dump_all_alias,
|
||||
'acli.reap': _tractor_reap,
|
||||
'acli.watch': watch,
|
||||
}
|
||||
|
||||
for _name, _fn in _TCLI_ALIASES.items():
|
||||
aliases[_name] = _fn
|
||||
|
||||
|
||||
# xontrib protocol hooks (for `xontrib load tractor_diag`).
|
||||
# also harmless when sourced directly.
|
||||
def _load_xontrib_(xsh, **_):
|
||||
return {}
|
||||
|
||||
|
||||
def _unload_xontrib_(xsh, **_):
|
||||
for name in _TCLI_ALIASES:
|
||||
aliases.pop(name, None)
|
||||
return {}
|
||||
Loading…
Reference in New Issue