Name every `ActorNursery` binding `an` in tests/examples

Convention sweep (user req): all `tractor.open_nursery()`
bindings in test + example code use `an: ActorNursery` (`n`,
`nursery` + several tractor-nurseries confusingly named `tn`
are renamed); `trio.open_nursery()` bindings stay `tn` (incl.
`concurrent_actors_primes.py`'s inner trio nursery, renamed
`n` -> `tn` to match).

Purely mechanical, function-scoped renames — prose "nursery"/
"an" in docstrings/comments untouched; func-arg kwargs like
`portal.run(func, n=value)` untouched.

Gate: renamed test modules green on `trio`; full debugger suite
(28p/6s) + example-runner (21p) green.

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
drop_ria_nursery
Gud Boi 2026-07-06 13:26:55 -04:00
parent a297a32af6
commit ad42871e47
23 changed files with 82 additions and 82 deletions

View File

@ -12,9 +12,9 @@ async def movie_theatre_question():
async def main():
"""The main ``tractor`` routine.
"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
portal = await n.start_actor(
portal = await an.start_actor(
'frank',
# enable the actor to run funcs from this current module
enable_modules=[__name__],

View File

@ -15,9 +15,9 @@ async def stream_forever() -> AsyncIterator[int]:
async def main():
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
portal = await n.start_actor(
portal = await an.start_actor(
'donny',
enable_modules=[__name__],
)

View File

@ -15,10 +15,10 @@ async def name_error():
async def spawn_error():
""""A nested nursery that triggers another ``NameError``.
"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
return await tractor.to_actor.run(
name_error,
an=n,
an=an,
name='name_error_1',
)

View File

@ -17,10 +17,10 @@ async def name_error():
async def spawn_error():
""""A nested nursery that triggers another ``NameError``.
"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
return await tractor.to_actor.run(
name_error,
an=n,
an=an,
name='name_error_1',
)

View File

@ -21,8 +21,8 @@ async def main() -> None:
async with tractor.open_nursery(
debug_mode=True,
) as n:
portal = await n.start_actor(
) as an:
portal = await an.start_actor(
'ctx_child',
# XXX: we don't enable the current module in order

View File

@ -6,14 +6,14 @@ async def die():
async def main():
async with tractor.open_nursery() as tn:
async with tractor.open_nursery() as an:
debug_actor = await tn.start_actor(
debug_actor = await an.start_actor(
'debugged_boi',
enable_modules=[__name__],
debug_mode=True,
)
crash_boi = await tn.start_actor(
crash_boi = await an.start_actor(
'crash_boi',
enable_modules=[__name__],
# debug_mode=True,

View File

@ -17,11 +17,11 @@ async def main():
tractor.open_nursery(
debug_mode=True,
# loglevel='debug' # ?XXX required?
) as n,
) as an,
trio.open_nursery() as tn,
):
# spawn the actor..
portal = await n.start_actor(
portal = await an.start_actor(
'key_error',
enable_modules=[__name__],
)

View File

@ -74,10 +74,10 @@ async def cancelled_before_pause(
async def main():
async with tractor.open_nursery(
debug_mode=True,
) as n:
) as an:
await tractor.to_actor.run(
cancelled_before_pause,
an=n,
an=an,
)
# ensure the same works in the root actor!

View File

@ -58,8 +58,8 @@ async def main():
debug_mode=True,
enable_transports=[tpt],
loglevel='devx',
) as n:
p = await n.start_actor(
) as an:
p = await an.start_actor(
'bp_boi',
enable_modules=[__name__],
)

View File

@ -17,13 +17,13 @@ async def main():
async with tractor.open_nursery(
debug_mode=True,
loglevel='cancel',
) as n:
) as an:
# parks awaiting a result which only arrives once the
# user quits (`BdbQuit`s) the child's REPL loop.
await tractor.to_actor.run(
breakpoint_forever,
an=n,
an=an,
)

View File

@ -50,8 +50,8 @@ async def trio_to_aio_echo_server(
async def main():
async with tractor.open_nursery() as n:
p = await n.start_actor(
async with tractor.open_nursery() as an:
p = await an.start_actor(
'aio_server',
enable_modules=[__name__],
infect_asyncio=True,

View File

@ -29,9 +29,9 @@ async def main() -> None:
))
await proc.wait()
# await trio.sleep_forever()
# async with tractor.open_nursery() as n:
# async with tractor.open_nursery() as an:
# portal = await n.start_actor(
# portal = await an.start_actor(
# 'rpc_server',
# enable_modules=[__name__],
# )

View File

@ -55,7 +55,7 @@ async def worker_pool(workers=4):
Yes, the workers stay alive (and ready for work) until you close
the context.
"""
async with tractor.open_nursery() as tn:
async with tractor.open_nursery() as an:
portals = []
snd_chan, recv_chan = trio.open_memory_channel(len(PRIMES))
@ -65,7 +65,7 @@ async def worker_pool(workers=4):
# this starts a new sub-actor (process + trio runtime) and
# stores it's "portal" for later use to "submit jobs" (ugh).
portals.append(
await tn.start_actor(
await an.start_actor(
f'worker_{i}',
enable_modules=[__name__],
)
@ -80,10 +80,10 @@ async def worker_pool(workers=4):
async def send_result(func, value, portal):
await snd_chan.send((value, await portal.run(func, n=value)))
async with trio.open_nursery() as n:
async with trio.open_nursery() as tn:
for value, portal in zip(sequence, itertools.cycle(portals)):
n.start_soon(
tn.start_soon(
send_result,
worker_func,
value,
@ -98,7 +98,7 @@ async def worker_pool(workers=4):
yield _map
# tear down all "workers" on pool close
await tn.cancel()
await an.cancel()
async def main():

View File

@ -7,17 +7,17 @@ async def assert_err():
async def main():
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
real_actors = []
for i in range(3):
real_actors.append(await n.start_actor(
real_actors.append(await an.start_actor(
f'actor_{i}',
enable_modules=[__name__],
))
# run one one-shot task actor that will fail immediately;
# its error raises right here in the caller's task..
await tractor.to_actor.run(assert_err, an=n)
await tractor.to_actor.run(assert_err, an=an)
# ..as a ``RemoteActorError`` containing an ``AssertionError``
# and all the other actors have been cancelled

View File

@ -31,9 +31,9 @@ async def simple_rpc(
async def main() -> None:
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
portal = await n.start_actor(
portal = await an.start_actor(
'rpc_server',
enable_modules=[__name__],
)

View File

@ -46,9 +46,9 @@ async def test_reg_then_unreg(
async with tractor.open_nursery(
registry_addrs=[reg_addr],
) as n:
) as an:
portal = await n.start_actor('actor', enable_modules=[__name__])
portal = await an.start_actor('actor', enable_modules=[__name__])
uid = portal.channel.aid.uid
async with tractor.get_registry(reg_addr) as aportal:
@ -62,7 +62,7 @@ async def test_reg_then_unreg(
# XXX: can we figure out what the listen addr will be?
assert sockaddrs
await n.cancel() # tear down nursery
await an.cancel() # tear down nursery
await trio.sleep(0.1)
assert uid not in aportal.actor._registry
@ -89,9 +89,9 @@ async def test_reg_then_unreg_maddr(
async with tractor.open_nursery(
registry_addrs=[maddr_str],
) as n:
) as an:
portal = await n.start_actor(
portal = await an.start_actor(
'actor_maddr',
enable_modules=[__name__],
)
@ -105,7 +105,7 @@ async def test_reg_then_unreg_maddr(
sockaddrs = actor._registry[uid]
assert sockaddrs
await n.cancel()
await an.cancel()
await trio.sleep(0.1)
assert uid not in aportal.actor._registry

View File

@ -219,7 +219,7 @@ def test_dynamic_pub_sub(
tractor.open_nursery(
registry_addrs=[reg_addr],
debug_mode=debug_mode,
) as n,
) as an,
# bg-schedules the forever-streaming
# one-shots below; the user-cancel raise
# cancels them all, each reaping its
@ -237,7 +237,7 @@ def test_dynamic_pub_sub(
partial(
tractor.to_actor.run,
publisher,
an=n,
an=an,
)
)
@ -249,7 +249,7 @@ def test_dynamic_pub_sub(
partial(
tractor.to_actor.run,
consumer,
an=n,
an=an,
name=f'consumer_{sub}',
subs=[sub],
)
@ -260,7 +260,7 @@ def test_dynamic_pub_sub(
partial(
tractor.to_actor.run,
consumer,
an=n,
an=an,
name='consumer_dynamic',
subs=list(_registry.keys()),
)
@ -370,10 +370,10 @@ def test_reqresp_ontopof_streaming():
timeout = 4
with trio.move_on_after(timeout):
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
# name of this actor will be same as target func
portal = await n.start_actor(
portal = await an.start_actor(
'dual_tasks',
enable_modules=[__name__]
)
@ -436,9 +436,9 @@ def test_sigint_both_stream_types():
async def main():
with trio.fail_after(timeout):
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
# name of this actor will be same as target func
portal = await n.start_actor(
portal = await an.start_actor(
'2_way',
enable_modules=[__name__]
)
@ -551,8 +551,8 @@ def test_local_task_fanout_from_stream(
async with tractor.open_nursery(
debug_mode=debug_mode,
) as tn:
p: tractor.Portal = await tn.start_actor(
) as an:
p: tractor.Portal = await an.start_actor(
'inf_streamer',
enable_modules=[__name__],
)

View File

@ -126,7 +126,7 @@ def test_remote_error(
async def main():
async with tractor.open_nursery(
registry_addrs=[reg_addr],
) as nursery:
) as an:
# `to_actor.run()` blocks on the one-shot's result and
# raises the remote error directly here in the caller's
@ -135,7 +135,7 @@ def test_remote_error(
try:
await tractor.to_actor.run(
assert_err,
an=nursery,
an=an,
name='errorer',
**args
)
@ -248,16 +248,16 @@ def test_cancel_single_subactor(
'''
async with tractor.open_nursery(
registry_addrs=[reg_addr],
) as nursery:
) as an:
portal = await nursery.start_actor(
portal = await an.start_actor(
'nothin', enable_modules=[__name__],
)
assert (await portal.run(do_nothing)) is None
if mechanism == 'nursery_cancel':
# would hang otherwise
await nursery.cancel()
await an.cancel()
else:
raise mechanism
@ -289,8 +289,8 @@ async def test_cancel_infinite_streamer(
trio.fail_after(4),
trio.move_on_after(1) as cancel_scope
):
async with tractor.open_nursery() as n:
portal = await n.start_actor(
async with tractor.open_nursery() as an:
portal = await an.start_actor(
'donny',
enable_modules=[__name__],
)
@ -303,7 +303,7 @@ async def test_cancel_infinite_streamer(
# we support trio's cancellation system
assert cancel_scope.cancelled_caught
assert n.cancel_called
assert an.cancel_called
@pytest.mark.parametrize(
@ -698,7 +698,7 @@ async def test_nested_multierrors(
async with fail_after_w_trace(timeout):
try:
async with (
tractor.open_nursery() as nursery,
tractor.open_nursery() as an,
trio.open_nursery() as tn,
):
for i in range(subactor_breadth):
@ -706,7 +706,7 @@ async def test_nested_multierrors(
partial(
tractor.to_actor.run,
spawn_and_error,
an=nursery,
an=an,
name=f'spawner_{i}',
breadth=subactor_breadth,
depth=depth,
@ -792,8 +792,8 @@ def test_cancel_via_SIGINT(
with trio.fail_after(2):
async with tractor.open_nursery(
registry_addrs=[reg_addr],
) as tn:
await tn.start_actor('sucka')
) as an:
await an.start_actor('sucka')
if 'mp' in start_method:
time.sleep(0.1)
os.kill(pid, signal.SIGINT)
@ -1054,8 +1054,8 @@ def test_fast_graceful_cancel_when_spawn_task_in_soft_proc_wait_for_daemon(
start = time.time()
try:
async with trio.open_nursery() as nurse:
async with tractor.open_nursery() as tn:
p = await tn.start_actor(
async with tractor.open_nursery() as an:
p = await an.start_actor(
'fast_boi',
enable_modules=[__name__],
)

View File

@ -156,8 +156,8 @@ def test_actor_managed_trio_nursery_task_error_cancels_aio(
async def main():
# cancel the nursery shortly after boot
async with tractor.open_nursery() as n:
p = await n.start_actor(
async with tractor.open_nursery() as an:
p = await an.start_actor(
'nursery_mngr',
infect_asyncio=asyncio_mode, # TODO, is this enabling debug mode?
enable_modules=[__name__],

View File

@ -163,12 +163,12 @@ def test_do_not_swallow_error_before_started_by_remote_contextcancelled(
async def main():
async with tractor.open_nursery(
debug_mode=debug_mode,
) as n:
portal = await n.start_actor(
) as an:
portal = await an.start_actor(
'errorer',
enable_modules=[__name__],
)
await n.start_actor(
await an.start_actor(
'sleeper',
enable_modules=[__name__],
)

View File

@ -139,9 +139,9 @@ async def test_required_args(callwith_expecterror):
with pytest.raises(err):
await func(**kwargs)
else:
async with tractor.open_nursery() as n:
async with tractor.open_nursery() as an:
portal = await n.start_actor(
portal = await an.start_actor(
name='pubber',
enable_modules=[__name__],
)
@ -180,7 +180,7 @@ def test_multi_actor_subs_arbiter_pub(
tractor.open_nursery(
registry_addrs=[reg_addr],
enable_modules=[__name__],
) as n,
) as an,
trio.open_nursery() as tn,
):
@ -188,7 +188,7 @@ def test_multi_actor_subs_arbiter_pub(
if pub_actor == 'streamer':
# start the publisher as a daemon
master_portal = await n.start_actor(
master_portal = await an.start_actor(
'streamer',
enable_modules=[__name__],
)
@ -215,11 +215,11 @@ def test_multi_actor_subs_arbiter_pub(
):
pass # expected once we `cancel_actor()` below
even_portal = await n.start_actor(
even_portal = await an.start_actor(
'evens',
enable_modules=[__name__],
)
odd_portal = await n.start_actor(
odd_portal = await an.start_actor(
'odds',
enable_modules=[__name__],
)
@ -294,9 +294,9 @@ def test_single_subactor_pub_multitask_subs(
async with tractor.open_nursery(
registry_addrs=[reg_addr],
enable_modules=[__name__],
) as n:
) as an:
portal = await n.start_actor(
portal = await an.start_actor(
'streamer',
enable_modules=[__name__],
)

View File

@ -107,13 +107,13 @@ def test_rpc_errors(
# do that if actually debugging subactor but keep it
# disabled for the test.
# debug_mode=True,
) as n:
) as an:
actor = tractor.current_actor()
assert actor.is_registrar
await tractor.to_actor.run(
sleep_back_actor,
an=n,
an=an,
actor_name=subactor_requests_to,
name='subactor',

View File

@ -202,10 +202,10 @@ def test_loglevel_propagated_to_subactor(
start_method=start_method,
registry_addrs=[reg_addr],
) as tn:
) as an:
await tractor.to_actor.run(
check_loglevel,
an=tn,
an=an,
loglevel=level,
level=level,
)