tractor/examples/debugging/root_timeout_while_child_cr...

44 lines
1.0 KiB
Python
Raw Normal View History

import trio
import tractor
async def key_error():
"Raise a ``NameError``"
return {}['doggy']
async def main():
'''
Root is fail-after-cancelled while blocking and child RPC fails
simultaneously.
'''
Port debugging examples off `run_in_actor` The 8 `examples/debugging/` scripts driven by the pexpect'd `test_debugger.py` REPL-flows (#477 removal), - blocking one-shots (`subactor_error`, `subactor_breakpoint`, `shielded_pause`): straight `to_actor.run(fn, an=an)` — the boxed error/`BdbQuit` raises in the root's task. - `multi_subactors`: introduces the "collect all errors" pattern — each one-shot catches + stashes its `RemoteActorError` (vs raising) so no child's crash cancels its siblings before they've had their own REPL sessions, then a `BaseExceptionGroup` of the lot raises at the end; preserves the legacy teardown-reap REPL flow exactly (28/28 debugger suite unchanged). - `multi_nested_subactors_error_up_through_nurseries` + `root_cancelled_but_child_is_in_tty_lock`: recursive `spawn_until` levels each block on their one-shot child; the parallel spawner-trees run as bg task-nursery one-shots where the first tree's error cancels the other. - `multi_subactor_root_errors` + `root_timeout_while_child_crashed`: `start_actor()` + bg `Portal.run()` tasks so the root's own error/timeout races the already-crashed children, same as before. - `sync_bp`: TODO-comment x-ref update only. `test_debugger.py`: the nested-nurseries test's final-output patterns update to the new relay shape — the LAST-released leaf REPL's error chain wins each level's relay-vs-cancel race and relays as a `collapse_eg()`-annotated collapsed chain, while the sibling tree is cancelled + absorbed. (The legacy teardown-reap grouped BOTH the `name_error` and bp-quit chains — explaining the previously-mysterious "extra" `src_uid`/`relay_uid` patterns noted in the old TODO.) Gate: `tests/devx/test_debugger.py` = 28 passed, 6 skipped — identical to the pre-migration baseline. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
2026-07-06 16:24:29 +00:00
async with (
tractor.open_nursery(
debug_mode=True,
# loglevel='debug' # ?XXX required?
) as n,
trio.open_nursery() as tn,
):
# spawn the actor..
portal = await n.start_actor(
'key_error',
enable_modules=[__name__],
)
print(
f'Child is up @ {portal.chan.aid.reprol()}'
)
Port debugging examples off `run_in_actor` The 8 `examples/debugging/` scripts driven by the pexpect'd `test_debugger.py` REPL-flows (#477 removal), - blocking one-shots (`subactor_error`, `subactor_breakpoint`, `shielded_pause`): straight `to_actor.run(fn, an=an)` — the boxed error/`BdbQuit` raises in the root's task. - `multi_subactors`: introduces the "collect all errors" pattern — each one-shot catches + stashes its `RemoteActorError` (vs raising) so no child's crash cancels its siblings before they've had their own REPL sessions, then a `BaseExceptionGroup` of the lot raises at the end; preserves the legacy teardown-reap REPL flow exactly (28/28 debugger suite unchanged). - `multi_nested_subactors_error_up_through_nurseries` + `root_cancelled_but_child_is_in_tty_lock`: recursive `spawn_until` levels each block on their one-shot child; the parallel spawner-trees run as bg task-nursery one-shots where the first tree's error cancels the other. - `multi_subactor_root_errors` + `root_timeout_while_child_crashed`: `start_actor()` + bg `Portal.run()` tasks so the root's own error/timeout races the already-crashed children, same as before. - `sync_bp`: TODO-comment x-ref update only. `test_debugger.py`: the nested-nurseries test's final-output patterns update to the new relay shape — the LAST-released leaf REPL's error chain wins each level's relay-vs-cancel race and relays as a `collapse_eg()`-annotated collapsed chain, while the sibling tree is cancelled + absorbed. (The legacy teardown-reap grouped BOTH the `name_error` and bp-quit chains — explaining the previously-mysterious "extra" `src_uid`/`relay_uid` patterns noted in the old TODO.) Gate: `tests/devx/test_debugger.py` = 28 passed, 6 skipped — identical to the pre-migration baseline. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
2026-07-06 16:24:29 +00:00
# ..then schedule its erroring task in the bg while the
# root blocks below.
tn.start_soon(portal.run, key_error)
2021-08-01 14:43:21 +00:00
# XXX: originally a bug caused by this is where root would enter
# the debugger and clobber the tty used by the repl even though
# child should have it locked.
with trio.fail_after(1):
await trio.Event().wait()
if __name__ == '__main__':
trio.run(main)