forked from goodboy/tractor
1
0
Fork 0
tractor/examples/debugging
Tyler Goodlet fc95c6719f Get multi-threaded sync-pausing fully workin!
The final issue was making sure we do the same thing on ctl-c/SIGINT
from the user. That is, if there's already a bg-thread in REPL, we
`log.pdb()` about SIGINT shielding and re-draw the prompt; the same UX
as normal actor-runtime-task behaviour.

Reasons this wasn't workin.. and the fix:
- `.pause_from_sync()` was overriding the local `repl` var with `None`
  delivered by (transitive) calls to `_pause(debug_func=None)`.. so
  remove all that and only assign it OAOO prior to thread-type case
  branching.
- always call `DebugStatus.shield_sigint()` as needed from all requesting
  threads/tasks:
  - in `_pause_from_bg_root_thread()` BEFORE calling `._pause()` AND BEFORE
    yielding back to the bg-thread via `.started(out)` to ensure we're
    definitely overriding the handler in the `trio`-main-thread task
    before unblocking the requesting bg-thread.
  - from any requesting bg-thread in the root actor such that both its
    main-`trio`-thread scheduled task (as per above bullet) AND it are
    SIGINT shielded.
  - always call `.shield_sigint()` BEFORE any `greenback._await()` case
    don't entirely grok why yet, but it works)?
  - for `greenback._await()` case always set `bg_task` to the current one..
- tweaks to the `SIGINT` handler, now renamed `sigint_shield()` so as
  not to name-collide with the methods when editor-searching:
  - always try to `repr()` the REPL thread/task "owner" as well as the
    active `PdbREPL` instance.
  - add `.devx()` notes around the prompt flushing deats and comments
    for any root-actor-bg-thread edge cases.

Related/supporting refinements:
- add `get_lock()`/`get_debug_req()` factory funcs since the plan is to
  eventually implement both as `@singleton` instances per actor.
- fix `acquire_debug_lock()`'s call-sig-bug for scheduling
  `request_root_stdio_lock()`..
- in `._pause()` only call `mk_pdb()` when `debug_func != None`.
- add some todo/warning notes around the `cls.repl = None` in
  `DebugStatus.release()`

`test_pause_from_sync()` tweaks:
- don't use a `attach_patts.copy()`, since we always `break` on match.
- do `pytest.fail()` on that ^ loop's fallthrough..
- pass `do_ctlc(child, patt=attach_key)` such that we always match the
  the current thread's name with the ctl-c triggered `.pdb()` emission.
- oh yeah, return the last `before: str` from `do_ctlc()`.
- in the script, flip `abandon_on_cancel=True` since when `False` it
  seems to cause `trio.run()` to hang on exit from the last bg-thread
  case?!?
2024-07-10 12:29:05 -04:00
..
asyncio_bp.py Provision for infected-`asyncio` debug mode support 2024-03-25 16:09:32 -04:00
debug_mode_hang.py Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
fast_error_in_root_after_spawn.py Fix type path to new `_supervise` mod 2021-10-23 15:54:40 -04:00
multi_daemon_subactors.py Tweaks to debugger examples 2024-05-28 09:22:59 -04:00
multi_nested_subactors_error_up_through_nurseries.py Tweaks to debugger examples 2024-05-28 09:22:59 -04:00
multi_subactor_root_errors.py Adjust debugger tests to expect depth > 1 crashes 2021-10-14 13:39:46 -04:00
multi_subactors.py Flip to `.pause()` in subactor bp example 2024-04-14 18:53:42 -04:00
open_ctx_modnofound.py Add basic module-not-found when opening a ctx eg. 2022-08-02 12:17:06 -04:00
per_actor_debug.py Tweaks to debugger examples 2024-05-28 09:22:59 -04:00
pm_in_subactor.py Add a `tractor.post_mortem()` API test + example 2024-05-30 16:03:28 -04:00
restore_builtin_breakpoint.py Restore `breakpoint()` hook after runtime exits 2023-05-15 00:47:29 -04:00
root_actor_breakpoint.py Drop `tractor.run()` from all examples 2021-05-07 11:21:40 -04:00
root_actor_breakpoint_forever.py Tweaks to debugger examples 2024-05-28 09:22:59 -04:00
root_actor_error.py Drop `tractor.run()` from all examples 2021-05-07 11:21:40 -04:00
root_cancelled_but_child_is_in_tty_lock.py Drop `tractor.run()` from all examples 2021-05-07 11:21:40 -04:00
root_timeout_while_child_crashed.py Docs and comments tidying 2021-08-01 10:44:13 -04:00
shielded_pause.py Finally, officially support shielded REPL-ing! 2024-05-30 17:52:24 -04:00
subactor_bp_in_ctx.py Add back in async gen loop 2022-07-27 11:40:02 -04:00
subactor_breakpoint.py Flip to `.pause()` in subactor bp example 2024-04-14 18:53:42 -04:00
subactor_error.py Tweaks to debugger examples 2024-05-28 09:22:59 -04:00
sync_bp.py Get multi-threaded sync-pausing fully workin! 2024-07-10 12:29:05 -04:00