Skip to content

Commit 9f0709e

Browse files
committed
Migrate test/smoketest imports + rename test file
Rename `tests/spawn/test_subint_forkserver.py` → `test_main_thread_forkserver.py` and migrate its imports + internal refs to the new canonical names: - `fork_from_worker_thread`, `wait_child` → from `tractor.spawn._main_thread_forkserver`. - `run_subint_in_worker_thread` → still from `_subint_forkserver` (variant-2 primitive). - Module docstring + tier-3 fixture + the `*_spawn_basic` test fn renamed for variant-1-honesty. - Orphan-harness subprocess argv flipped from `'subint_forkserver'` → `'main_thread_forkserver'`. `ai/conc-anal/subint_fork_from_main_thread_smoketest.py` imports split the same way. `tractor/spawn/_subint_forkserver.py` drops the backward- compat re-exports of the fork primitives — the only consumers (test file + smoketest) now import from `_main_thread_forkserver` directly. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent 5e83881 commit 9f0709e

3 files changed

Lines changed: 32 additions & 42 deletions

File tree

ai/conc-anal/subint_fork_from_main_thread_smoketest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@
8989
# the "zero tractor imports" isolation guarantee; now that
9090
# CPython-level feasibility is confirmed, the validated
9191
# primitives have moved into tractor proper.)
92-
from tractor.spawn._subint_forkserver import (
92+
from tractor.spawn._main_thread_forkserver import (
9393
fork_from_worker_thread,
94-
run_subint_in_worker_thread,
9594
wait_child,
9695
)
96+
from tractor.spawn._subint_forkserver import (
97+
run_subint_in_worker_thread,
98+
)
9799

98100

99101
# ----------------------------------------------------------------

tests/spawn/test_subint_forkserver.py renamed to tests/spawn/test_main_thread_forkserver.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
'''
2-
Integration exercises for the `tractor.spawn._subint_forkserver`
2+
Integration exercises for the `tractor.spawn._main_thread_forkserver`
33
submodule at three tiers:
44
55
1. the low-level primitives
6-
(`fork_from_worker_thread()` +
7-
`run_subint_in_worker_thread()`) driven from inside a real
6+
(`fork_from_worker_thread()` from `_main_thread_forkserver`
7+
+ `run_subint_in_worker_thread()` from
8+
`_subint_forkserver`) driven from inside a real
89
`trio.run()` in the parent process,
910
10-
2. the full `subint_forkserver_proc` spawn backend wired
11+
2. the full `main_thread_forkserver_proc` spawn backend wired
1112
through tractor's normal actor-nursery + portal-RPC
1213
machinery — i.e. `open_root_actor` + `open_nursery` +
1314
`run_in_actor` against a subactor spawned via fork from a
@@ -27,15 +28,15 @@
2728
in the *parent*. Tiers (1)+(2) here cover the primitives
2829
driven from inside `trio.run()` in the parent, and tier (3)
2930
(the `*_spawn_basic` test) drives the registered
30-
`subint_forkserver` spawn backend end-to-end against the
31-
tractor runtime.
31+
`main_thread_forkserver` spawn backend end-to-end against
32+
the tractor runtime.
3233
3334
Gating
3435
------
3536
- py3.14+ (via `concurrent.interpreters` presence)
3637
- no `--spawn-backend` restriction — the backend-level test
3738
flips `tractor.spawn._spawn._spawn_method` programmatically
38-
(via `try_set_start_method('subint_forkserver')`) and
39+
(via `try_set_start_method('main_thread_forkserver')`) and
3940
restores it on teardown, so these tests are independent of
4041
the session-level CLI backend choice.
4142
@@ -64,11 +65,13 @@
6465
# `tractor.spawn._subint` for why.
6566
pytest.importorskip('concurrent.interpreters')
6667

67-
from tractor.spawn._subint_forkserver import ( # noqa: E402
68+
from tractor.spawn._main_thread_forkserver import ( # noqa: E402
6869
fork_from_worker_thread,
69-
run_subint_in_worker_thread,
7070
wait_child,
7171
)
72+
from tractor.spawn._subint_forkserver import ( # noqa: E402
73+
run_subint_in_worker_thread,
74+
)
7275
from tractor.spawn import _spawn as _spawn_mod # noqa: E402
7376
from tractor.spawn._spawn import try_set_start_method # noqa: E402
7477

@@ -195,7 +198,7 @@ def test_fork_from_worker_thread_via_trio(
195198
deadline: float = 10.0
196199
with dump_on_hang(
197200
seconds=deadline,
198-
path='/tmp/subint_forkserver_baseline.dump',
201+
path='/tmp/main_thread_forkserver_baseline.dump',
199202
):
200203
pid: int = trio.run(
201204
partial(run_fork_in_non_trio_thread, deadline),
@@ -217,14 +220,14 @@ def test_fork_and_run_trio_in_child() -> None:
217220
`trio.run()` inside it on yet another worker thread.
218221
219222
This is the full "forkserver + trio-in-subint-in-child"
220-
pattern the proposed `subint_forkserver` spawn backend
223+
pattern the proposed `main_thread_forkserver` spawn backend
221224
would rest on.
222225
223226
'''
224227
deadline: float = 15.0
225228
with dump_on_hang(
226229
seconds=deadline,
227-
path='/tmp/subint_forkserver_trio_in_child.dump',
230+
path='/tmp/main_thread_forkserver_trio_in_child.dump',
228231
):
229232
pid: int = trio.run(
230233
partial(
@@ -237,7 +240,7 @@ def test_fork_and_run_trio_in_child() -> None:
237240

238241

239242
# ----------------------------------------------------------------
240-
# tier-3 backend test: drive the registered `subint_forkserver`
243+
# tier-3 backend test: drive the registered `main_thread_forkserver`
241244
# spawn backend end-to-end through tractor's actor-nursery +
242245
# portal-RPC machinery.
243246
# ----------------------------------------------------------------
@@ -260,7 +263,7 @@ async def _happy_path_forkserver(
260263
Parent-side harness: stand up a root actor, open an actor
261264
nursery, spawn one subactor via the currently-selected
262265
spawn backend (which this test will have flipped to
263-
`subint_forkserver`), run a trivial RPC through its
266+
`main_thread_forkserver`), run a trivial RPC through its
264267
portal, assert the round-trip result.
265268
266269
'''
@@ -304,19 +307,19 @@ def forkserver_spawn_method():
304307

305308

306309
@pytest.mark.timeout(60, method='thread')
307-
def test_subint_forkserver_spawn_basic(
310+
def test_main_thread_forkserver_spawn_basic(
308311
reg_addr: tuple[str, int | str],
309312
forkserver_spawn_method,
310313
) -> None:
311314
'''
312315
Happy-path: spawn ONE subactor via the
313-
`subint_forkserver` backend (parent-side fork from a
316+
`main_thread_forkserver` backend (parent-side fork from a
314317
main-interp worker thread), do a trivial portal-RPC
315318
round-trip, tear the nursery down cleanly.
316319
317320
If this passes, the "forkserver + tractor runtime" arch
318321
is proven end-to-end: the registered
319-
`subint_forkserver_proc` spawn target successfully
322+
`main_thread_forkserver_proc` spawn target successfully
320323
forks a child, the child runs `_actor_child_main()` +
321324
completes IPC handshake + serves an RPC, and the parent
322325
reaps via `_ForkedProc.wait()` without regressing any of
@@ -326,7 +329,7 @@ def test_subint_forkserver_spawn_basic(
326329
deadline: float = 20.0
327330
with dump_on_hang(
328331
seconds=deadline,
329-
path='/tmp/subint_forkserver_spawn_basic.dump',
332+
path='/tmp/main_thread_forkserver_spawn_basic.dump',
330333
):
331334
trio.run(
332335
partial(
@@ -340,7 +343,7 @@ def test_subint_forkserver_spawn_basic(
340343
# ----------------------------------------------------------------
341344
# tier-4 DRAFT: orphaned-subactor SIGINT survivability
342345
#
343-
# Motivating question: with `subint_forkserver`, the child's
346+
# Motivating question: with `main_thread_forkserver`, the child's
344347
# `trio.run()` lives on the fork-inherited worker thread which
345348
# is NOT `threading.main_thread()` — so trio cannot install its
346349
# `signal.set_wakeup_fd`-based SIGINT handler. If the parent
@@ -360,7 +363,7 @@ def test_subint_forkserver_spawn_basic(
360363
# Cross-backend generalization (decide after this passes):
361364
# - applicable to any backend whose subactors are separate OS
362365
# processes: `trio`, `mp_spawn`, `mp_forkserver`,
363-
# `subint_forkserver`.
366+
# `main_thread_forkserver`.
364367
# - NOT applicable to plain `subint` (subactors are in-process
365368
# subinterpreters, no orphan child process to SIGINT).
366369
# - move path: lift the harness script into
@@ -446,7 +449,7 @@ def _process_alive(pid: int) -> bool:
446449
return False
447450

448451

449-
# Known-gap test — `subint_forkserver` orphan-SIGINT
452+
# Known-gap test — `main_thread_forkserver` orphan-SIGINT
450453
# handling. See
451454
# `ai/conc-anal/subint_forkserver_orphan_sigint_hang_issue.md`.
452455
# `strict=True` so if a future fix closes the gap the
@@ -471,12 +474,12 @@ def test_orphaned_subactor_sigint_cleanup_DRAFT(
471474
) -> None:
472475
'''
473476
DRAFT — orphaned-subactor SIGINT survivability under the
474-
`subint_forkserver` backend.
477+
`main_thread_forkserver` backend.
475478
476479
Sequence:
477480
1. Spawn a harness subprocess that brings up a root
478481
actor + one `sleep_forever` subactor via
479-
`subint_forkserver`.
482+
`main_thread_forkserver`.
480483
2. Read the harness's stdout for `PARENT_READY=<pid>`
481484
and `CHILD_PID=<pid>` markers (confirms the
482485
parent→child IPC handshake completed).
@@ -524,7 +527,7 @@ def test_orphaned_subactor_sigint_cleanup_DRAFT(
524527
[
525528
sys.executable,
526529
str(script_path),
527-
'subint_forkserver',
530+
'main_thread_forkserver',
528531
host,
529532
str(port),
530533
],
@@ -577,7 +580,7 @@ def test_orphaned_subactor_sigint_cleanup_DRAFT(
577580

578581
pytest.fail(
579582
f'Orphan subactor (pid={child_pid}) did NOT exit '
580-
f'within 10s of SIGINT under `subint_forkserver` '
583+
f'within 10s of SIGINT under `main_thread_forkserver` '
581584
f'→ trio on non-main thread did not observe the '
582585
f'default CPython KeyboardInterrupt; backend needs '
583586
f'explicit SIGINT plumbing.'

tractor/spawn/_subint_forkserver.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,6 @@
154154
from tractor.log import get_logger
155155
from ._subint import _has_subints
156156

157-
# Backward-compat re-exports of the fork primitives whose
158-
# canonical home is now `_main_thread_forkserver`. Kept here
159-
# transiently so existing
160-
# `from tractor.spawn._subint_forkserver import ...` callsites
161-
# in the tests + the conc-anal smoketest keep resolving;
162-
# dropped once a follow-up commit migrates those imports to
163-
# the new module.
164-
from ._main_thread_forkserver import (
165-
_close_inherited_fds as _close_inherited_fds,
166-
_format_child_exit as _format_child_exit,
167-
fork_from_worker_thread as fork_from_worker_thread,
168-
wait_child as wait_child,
169-
_ForkedProc as _ForkedProc,
170-
)
171-
172157
if TYPE_CHECKING:
173158
from tractor.discovery._addr import UnwrappedAddress
174159
from tractor.runtime._portal import Portal

0 commit comments

Comments
 (0)