forked from goodboy/tractor
Typing fixes, simplify `_set_trace()`
parent
2cdf6bd8ce
commit
a4396e78ee
|
@ -31,6 +31,7 @@ from typing import (
|
||||||
AsyncIterator,
|
AsyncIterator,
|
||||||
AsyncGenerator,
|
AsyncGenerator,
|
||||||
)
|
)
|
||||||
|
from types import FrameType
|
||||||
|
|
||||||
import tractor
|
import tractor
|
||||||
import trio
|
import trio
|
||||||
|
@ -380,7 +381,7 @@ async def wait_for_parent_stdin_hijack(
|
||||||
log.debug(f"Child {actor_uid} released parent stdio lock")
|
log.debug(f"Child {actor_uid} released parent stdio lock")
|
||||||
|
|
||||||
|
|
||||||
def mk_mpdb() -> (MultiActorPdb, Callable):
|
def mk_mpdb() -> tuple[MultiActorPdb, Callable]:
|
||||||
|
|
||||||
pdb = MultiActorPdb()
|
pdb = MultiActorPdb()
|
||||||
signal.signal = pdbpp.hideframe(signal.signal)
|
signal.signal = pdbpp.hideframe(signal.signal)
|
||||||
|
@ -534,9 +535,10 @@ async def _breakpoint(
|
||||||
|
|
||||||
_pdb_release_hook = teardown
|
_pdb_release_hook = teardown
|
||||||
|
|
||||||
frame = sys._getframe()
|
# frame = sys._getframe()
|
||||||
last_f = frame.f_back
|
# last_f = frame.f_back
|
||||||
last_f.f_globals['__tracebackhide__'] = True
|
# last_f.f_globals['__tracebackhide__'] = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# block here one (at the appropriate frame *up*) where
|
# block here one (at the appropriate frame *up*) where
|
||||||
# ``breakpoint()`` was awaited and begin handling stdio.
|
# ``breakpoint()`` was awaited and begin handling stdio.
|
||||||
|
@ -658,24 +660,25 @@ def shield_sigint(
|
||||||
|
|
||||||
|
|
||||||
def _set_trace(
|
def _set_trace(
|
||||||
actor: Optional[tractor.Actor] = None,
|
actor: Optional[tractor._actor.Actor] = None,
|
||||||
pdb: Optional[MultiActorPdb] = None,
|
pdb: Optional[MultiActorPdb] = None,
|
||||||
):
|
):
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
actor = actor or tractor.current_actor()
|
actor = actor or tractor.current_actor()
|
||||||
|
|
||||||
|
# XXX: on latest ``pdbpp`` i guess we don't need this?
|
||||||
# frame = sys._getframe()
|
# frame = sys._getframe()
|
||||||
# last_f = frame.f_back
|
# last_f = frame.f_back
|
||||||
# last_f.f_globals['__tracebackhide__'] = True
|
# last_f.f_globals['__tracebackhide__'] = True
|
||||||
|
|
||||||
|
# start 2 levels up in user code
|
||||||
|
frame: FrameType = sys._getframe()
|
||||||
|
if frame:
|
||||||
|
frame = frame.f_back.f_back # type: ignore
|
||||||
|
|
||||||
if pdb and actor is not None:
|
if pdb and actor is not None:
|
||||||
log.pdb(f"\nAttaching pdb to actor: {actor.uid}\n")
|
log.pdb(f"\nAttaching pdb to actor: {actor.uid}\n")
|
||||||
|
|
||||||
pdb.set_trace(
|
|
||||||
# start 2 levels up in user code
|
|
||||||
frame=sys._getframe().f_back.f_back,
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pdb, undo_sigint = mk_mpdb()
|
pdb, undo_sigint = mk_mpdb()
|
||||||
|
|
||||||
|
@ -683,12 +686,7 @@ def _set_trace(
|
||||||
global _local_task_in_debug, _pdb_release_hook
|
global _local_task_in_debug, _pdb_release_hook
|
||||||
_local_task_in_debug = 'sync'
|
_local_task_in_debug = 'sync'
|
||||||
|
|
||||||
_pdb_release_hook = undo_sigint
|
pdb.set_trace(frame=frame)
|
||||||
|
|
||||||
pdb.set_trace(
|
|
||||||
# start 2 levels up in user code
|
|
||||||
frame=sys._getframe().f_back.f_back,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
breakpoint = partial(
|
breakpoint = partial(
|
||||||
|
@ -698,7 +696,7 @@ breakpoint = partial(
|
||||||
|
|
||||||
|
|
||||||
def _post_mortem(
|
def _post_mortem(
|
||||||
actor: tractor.Actor,
|
actor: tractor._actor.Actor,
|
||||||
pdb: MultiActorPdb,
|
pdb: MultiActorPdb,
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Reference in New Issue