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..?
runtime_to_msgspec
Tyler Goodlet 2024-05-22 15:11:21 -04:00
parent 9eb74560ad
commit c6f599b1be
2 changed files with 14 additions and 6 deletions

View File

@ -33,6 +33,7 @@ from .log import (
get_logger, get_logger,
) )
from . import _state from . import _state
from .devx import _debug
from .to_asyncio import run_as_asyncio_guest from .to_asyncio import run_as_asyncio_guest
from ._runtime import ( from ._runtime import (
async_main, async_main,
@ -96,7 +97,6 @@ def _mp_main(
def _trio_main( def _trio_main(
actor: Actor, actor: Actor,
*, *,
parent_addr: tuple[str, int] | None = None, parent_addr: tuple[str, int] | None = None,
@ -107,7 +107,9 @@ def _trio_main(
Entry point for a `trio_run_in_process` subactor. Entry point for a `trio_run_in_process` subactor.
''' '''
__tracebackhide__: bool = True # __tracebackhide__: bool = True
_debug.hide_runtime_frames()
_state._current_actor = actor _state._current_actor = actor
trio_main = partial( trio_main = partial(
async_main, async_main,
@ -146,7 +148,6 @@ def _trio_main(
+ +
actor_info actor_info
) )
finally: finally:
log.info( log.info(
'Subactor terminated\n' 'Subactor terminated\n'

View File

@ -91,12 +91,16 @@ async def open_root_actor(
# and that this call creates it. # and that this call creates it.
ensure_registry: bool = False, ensure_registry: bool = False,
hide_tb: bool = True,
) -> Actor: ) -> Actor:
''' '''
Runtime init entry point for ``tractor``. 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`? # TODO: stick this in a `@cm` defined in `devx._debug`?
# #
# Override the global debugger hook to make it play nice with # 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! # usage by a clobbered TTY's stdstreams!
def block_bps(*args, **kwargs): def block_bps(*args, **kwargs):
raise RuntimeError( 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' 'Welp, `tractor` blocks `breakpoint()` built-in calls by default!\n'
'If you need to use it please install `greenback` and set ' 'If you need to use it please install `greenback` and set '
'`debug_mode=True` when opening the runtime ' '`debug_mode=True` when opening the runtime '
@ -133,7 +137,9 @@ async def open_root_actor(
) )
sys.breakpointhook = block_bps 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 # attempt to retreive ``trio``'s sigint handler and stash it
# on our debugger lock state. # on our debugger lock state.
@ -203,6 +209,7 @@ async def open_root_actor(
): ):
loglevel = 'PDB' loglevel = 'PDB'
elif debug_mode: elif debug_mode:
raise RuntimeError( raise RuntimeError(
"Debug mode is only supported for the `trio` backend!" "Debug mode is only supported for the `trio` backend!"