Mv `.hide_runtime_frames()` -> `.devx._frame_stack`
A much more relevant module for a call-stack-frame hider ;)repl_fixture
parent
5024e71d8e
commit
69267ae656
|
@ -35,7 +35,7 @@ from .log import (
|
||||||
)
|
)
|
||||||
from . import _state
|
from . import _state
|
||||||
from .devx import (
|
from .devx import (
|
||||||
debug,
|
_frame_stack,
|
||||||
pformat,
|
pformat,
|
||||||
)
|
)
|
||||||
from .to_asyncio import run_as_asyncio_guest
|
from .to_asyncio import run_as_asyncio_guest
|
||||||
|
@ -116,7 +116,7 @@ def _trio_main(
|
||||||
Entry point for a `trio_run_in_process` subactor.
|
Entry point for a `trio_run_in_process` subactor.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
debug.hide_runtime_frames()
|
_frame_stack.hide_runtime_frames()
|
||||||
|
|
||||||
_state._current_actor = actor
|
_state._current_actor = actor
|
||||||
trio_main = partial(
|
trio_main = partial(
|
||||||
|
|
|
@ -44,7 +44,10 @@ from ._runtime import (
|
||||||
# Arbiter as Registry,
|
# Arbiter as Registry,
|
||||||
async_main,
|
async_main,
|
||||||
)
|
)
|
||||||
from .devx import debug
|
from .devx import (
|
||||||
|
debug,
|
||||||
|
_frame_stack,
|
||||||
|
)
|
||||||
from . import _spawn
|
from . import _spawn
|
||||||
from . import _state
|
from . import _state
|
||||||
from . import log
|
from . import log
|
||||||
|
@ -223,7 +226,7 @@ async def open_root_actor(
|
||||||
len(enable_transports) == 1
|
len(enable_transports) == 1
|
||||||
), 'No multi-tpt support yet!'
|
), 'No multi-tpt support yet!'
|
||||||
|
|
||||||
debug.hide_runtime_frames()
|
_frame_stack.hide_runtime_frames()
|
||||||
__tracebackhide__: bool = hide_tb
|
__tracebackhide__: bool = hide_tb
|
||||||
|
|
||||||
# attempt to retreive ``trio``'s sigint handler and stash it
|
# attempt to retreive ``trio``'s sigint handler and stash it
|
||||||
|
|
|
@ -20,13 +20,18 @@ as it pertains to improving the grok-ability of our runtime!
|
||||||
|
|
||||||
'''
|
'''
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from contextlib import (
|
||||||
|
_GeneratorContextManager,
|
||||||
|
_AsyncGeneratorContextManager,
|
||||||
|
)
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import inspect
|
import inspect
|
||||||
|
import textwrap
|
||||||
from types import (
|
from types import (
|
||||||
FrameType,
|
FrameType,
|
||||||
FunctionType,
|
FunctionType,
|
||||||
MethodType,
|
MethodType,
|
||||||
# CodeType,
|
CodeType,
|
||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -34,6 +39,9 @@ from typing import (
|
||||||
Type,
|
Type,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import pdbp
|
||||||
|
from tractor.log import get_logger
|
||||||
|
import trio
|
||||||
from tractor.msg import (
|
from tractor.msg import (
|
||||||
pretty_struct,
|
pretty_struct,
|
||||||
NamespacePath,
|
NamespacePath,
|
||||||
|
@ -41,6 +49,8 @@ from tractor.msg import (
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
|
|
||||||
|
log = get_logger(__name__)
|
||||||
|
|
||||||
# TODO: yeah, i don't love this and we should prolly just
|
# TODO: yeah, i don't love this and we should prolly just
|
||||||
# write a decorator that actually keeps a stupid ref to the func
|
# write a decorator that actually keeps a stupid ref to the func
|
||||||
# obj..
|
# obj..
|
||||||
|
@ -301,3 +311,70 @@ def api_frame(
|
||||||
# error_set: set[BaseException],
|
# error_set: set[BaseException],
|
||||||
# ) -> TracebackType:
|
# ) -> TracebackType:
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
|
|
||||||
|
def hide_runtime_frames() -> dict[FunctionType, CodeType]:
|
||||||
|
'''
|
||||||
|
Hide call-stack frames for various std-lib and `trio`-API primitives
|
||||||
|
such that the tracebacks presented from our runtime are as minimized
|
||||||
|
as possible, particularly from inside a `PdbREPL`.
|
||||||
|
|
||||||
|
'''
|
||||||
|
# XXX HACKZONE XXX
|
||||||
|
# hide exit stack frames on nurseries and cancel-scopes!
|
||||||
|
# |_ so avoid seeing it when the `pdbp` REPL is first engaged from
|
||||||
|
# inside a `trio.open_nursery()` scope (with no line after it
|
||||||
|
# in before the block end??).
|
||||||
|
#
|
||||||
|
# TODO: FINALLY got this workin originally with
|
||||||
|
# `@pdbp.hideframe` around the `wrapper()` def embedded inside
|
||||||
|
# `_ki_protection_decoratior()`.. which is in the module:
|
||||||
|
# /home/goodboy/.virtualenvs/tractor311/lib/python3.11/site-packages/trio/_core/_ki.py
|
||||||
|
#
|
||||||
|
# -[ ] make an issue and patch for `trio` core? maybe linked
|
||||||
|
# to the long outstanding `pdb` one below?
|
||||||
|
# |_ it's funny that there's frame hiding throughout `._run.py`
|
||||||
|
# but not where it matters on the below exit funcs..
|
||||||
|
#
|
||||||
|
# -[ ] provide a patchset for the lonstanding
|
||||||
|
# |_ https://github.com/python-trio/trio/issues/1155
|
||||||
|
#
|
||||||
|
# -[ ] make a linked issue to ^ and propose allowing all the
|
||||||
|
# `._core._run` code to have their `__tracebackhide__` value
|
||||||
|
# configurable by a `RunVar` to allow getting scheduler frames
|
||||||
|
# if desired through configuration?
|
||||||
|
#
|
||||||
|
# -[ ] maybe dig into the core `pdb` issue why the extra frame is shown
|
||||||
|
# at all?
|
||||||
|
#
|
||||||
|
funcs: list[FunctionType] = [
|
||||||
|
trio._core._run.NurseryManager.__aexit__,
|
||||||
|
trio._core._run.CancelScope.__exit__,
|
||||||
|
_GeneratorContextManager.__exit__,
|
||||||
|
_AsyncGeneratorContextManager.__aexit__,
|
||||||
|
_AsyncGeneratorContextManager.__aenter__,
|
||||||
|
trio.Event.wait,
|
||||||
|
]
|
||||||
|
func_list_str: str = textwrap.indent(
|
||||||
|
"\n".join(f.__qualname__ for f in funcs),
|
||||||
|
prefix=' |_ ',
|
||||||
|
)
|
||||||
|
log.devx(
|
||||||
|
'Hiding the following runtime frames by default:\n'
|
||||||
|
f'{func_list_str}\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
codes: dict[FunctionType, CodeType] = {}
|
||||||
|
for ref in funcs:
|
||||||
|
# stash a pre-modified version of each ref's code-obj
|
||||||
|
# so it can be reverted later if needed.
|
||||||
|
codes[ref] = ref.__code__
|
||||||
|
pdbp.hideframe(ref)
|
||||||
|
#
|
||||||
|
# pdbp.hideframe(trio._core._run.NurseryManager.__aexit__)
|
||||||
|
# pdbp.hideframe(trio._core._run.CancelScope.__exit__)
|
||||||
|
# pdbp.hideframe(_GeneratorContextManager.__exit__)
|
||||||
|
# pdbp.hideframe(_AsyncGeneratorContextManager.__aexit__)
|
||||||
|
# pdbp.hideframe(_AsyncGeneratorContextManager.__aenter__)
|
||||||
|
# pdbp.hideframe(trio.Event.wait)
|
||||||
|
return codes
|
||||||
|
|
Loading…
Reference in New Issue