From c6f599b1beb4b5927cf69d051e908870908729f8 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 22 May 2024 15:11:21 -0400 Subject: [PATCH] Call `.devx._debug.hide_runtime_frames()` by default From both `open_root_actor()` and `._entry._trio_main()`. Other `breakpoint()`-from-sync-func fixes: - properly disable the default hook using `"0"` XD - offer a `hide_tb: bool` from `open_root_actor()`. - disable hiding the `._trio_main()` frame, bc pretty sure it doesn't help anyone (either way) when REPL-ing/tb-ing from a subactor..? --- tractor/_entry.py | 7 ++++--- tractor/_root.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tractor/_entry.py b/tractor/_entry.py index 750dc59..e22a4f1 100644 --- a/tractor/_entry.py +++ b/tractor/_entry.py @@ -33,6 +33,7 @@ from .log import ( get_logger, ) from . import _state +from .devx import _debug from .to_asyncio import run_as_asyncio_guest from ._runtime import ( async_main, @@ -96,7 +97,6 @@ def _mp_main( def _trio_main( - actor: Actor, *, parent_addr: tuple[str, int] | None = None, @@ -107,7 +107,9 @@ def _trio_main( Entry point for a `trio_run_in_process` subactor. ''' - __tracebackhide__: bool = True + # __tracebackhide__: bool = True + _debug.hide_runtime_frames() + _state._current_actor = actor trio_main = partial( async_main, @@ -146,7 +148,6 @@ def _trio_main( + actor_info ) - finally: log.info( 'Subactor terminated\n' diff --git a/tractor/_root.py b/tractor/_root.py index 7780699..a01ecd0 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -91,12 +91,16 @@ async def open_root_actor( # and that this call creates it. ensure_registry: bool = False, + hide_tb: bool = True, + ) -> Actor: ''' Runtime init entry point for ``tractor``. ''' - __tracebackhide__ = True + __tracebackhide__: bool = hide_tb + _debug.hide_runtime_frames() + # TODO: stick this in a `@cm` defined in `devx._debug`? # # Override the global debugger hook to make it play nice with @@ -125,7 +129,7 @@ async def open_root_actor( # usage by a clobbered TTY's stdstreams! def block_bps(*args, **kwargs): raise RuntimeError( - 'Trying to use `breakpoint()` eh?\n' + 'Trying to use `breakpoint()` eh?\n\n' 'Welp, `tractor` blocks `breakpoint()` built-in calls by default!\n' 'If you need to use it please install `greenback` and set ' '`debug_mode=True` when opening the runtime ' @@ -133,7 +137,9 @@ async def open_root_actor( ) sys.breakpointhook = block_bps - # os.environ['PYTHONBREAKPOINT'] = None + # lol ok, + # https://docs.python.org/3/library/sys.html#sys.breakpointhook + os.environ['PYTHONBREAKPOINT'] = "0" # attempt to retreive ``trio``'s sigint handler and stash it # on our debugger lock state. @@ -203,6 +209,7 @@ async def open_root_actor( ): loglevel = 'PDB' + elif debug_mode: raise RuntimeError( "Debug mode is only supported for the `trio` backend!"