forked from goodboy/tractor
Add and use a pdb instance factory
parent
21dccb2e79
commit
8f4bbf1cbf
|
@ -283,9 +283,9 @@ async def _hijack_stdin_for_child(
|
||||||
assert await stream.receive() == 'pdb_unlock'
|
assert await stream.receive() == 'pdb_unlock'
|
||||||
|
|
||||||
except (
|
except (
|
||||||
# BaseException,
|
BaseException,
|
||||||
trio.MultiError,
|
# trio.MultiError,
|
||||||
Exception,
|
# Exception,
|
||||||
# trio.BrokenResourceError,
|
# trio.BrokenResourceError,
|
||||||
# trio.Cancelled, # by local cancellation
|
# trio.Cancelled, # by local cancellation
|
||||||
# trio.ClosedResourceError, # by self._rx_chan
|
# trio.ClosedResourceError, # by self._rx_chan
|
||||||
|
@ -301,7 +301,7 @@ async def _hijack_stdin_for_child(
|
||||||
if lock and lock.locked():
|
if lock and lock.locked():
|
||||||
lock.release()
|
lock.release()
|
||||||
|
|
||||||
if isinstance(err, trio.Cancelled):
|
# if isinstance(err, trio.Cancelled):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -381,6 +381,28 @@ 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):
|
||||||
|
|
||||||
|
pdb = MultiActorPdb()
|
||||||
|
signal.signal = pdbpp.hideframe(signal.signal)
|
||||||
|
orig_handler = signal.signal(
|
||||||
|
signal.SIGINT,
|
||||||
|
partial(shield_sigint, pdb_obj=pdb),
|
||||||
|
)
|
||||||
|
pdb.allow_kbdint = True
|
||||||
|
pdb.nosigint = True
|
||||||
|
|
||||||
|
# TODO: add this as method on our pdb obj?
|
||||||
|
def undo_sigint():
|
||||||
|
# restore original sigint handler
|
||||||
|
signal.signal(
|
||||||
|
signal.SIGINT,
|
||||||
|
orig_handler
|
||||||
|
)
|
||||||
|
|
||||||
|
return pdb, undo_sigint
|
||||||
|
|
||||||
|
|
||||||
async def _breakpoint(
|
async def _breakpoint(
|
||||||
|
|
||||||
debug_func,
|
debug_func,
|
||||||
|
@ -402,15 +424,7 @@ async def _breakpoint(
|
||||||
# scope here???
|
# scope here???
|
||||||
# with trio.CancelScope(shield=shield):
|
# with trio.CancelScope(shield=shield):
|
||||||
|
|
||||||
pdb = MultiActorPdb()
|
pdb, undo_sigint = mk_mpdb()
|
||||||
signal.signal = pdbpp.hideframe(signal.signal)
|
|
||||||
orig_handler = signal.signal(
|
|
||||||
signal.SIGINT,
|
|
||||||
partial(shield_sigint, pdb_obj=pdb),
|
|
||||||
)
|
|
||||||
pdb.allow_kbdint = True
|
|
||||||
pdb.nosigint = True
|
|
||||||
|
|
||||||
actor = tractor.current_actor()
|
actor = tractor.current_actor()
|
||||||
task_name = trio.lowlevel.current_task().name
|
task_name = trio.lowlevel.current_task().name
|
||||||
|
|
||||||
|
@ -449,11 +463,9 @@ async def _breakpoint(
|
||||||
def child_release_hook():
|
def child_release_hook():
|
||||||
# _local_task_in_debug = None
|
# _local_task_in_debug = None
|
||||||
_local_pdb_complete.set()
|
_local_pdb_complete.set()
|
||||||
|
|
||||||
# restore original sigint handler
|
# restore original sigint handler
|
||||||
signal.signal(
|
undo_sigint()
|
||||||
signal.SIGINT,
|
|
||||||
orig_handler
|
|
||||||
)
|
|
||||||
|
|
||||||
# assign unlock callback for debugger teardown hooks
|
# assign unlock callback for debugger teardown hooks
|
||||||
# _pdb_release_hook = _local_pdb_complete.set
|
# _pdb_release_hook = _local_pdb_complete.set
|
||||||
|
@ -523,10 +535,7 @@ async def _breakpoint(
|
||||||
_local_pdb_complete.set()
|
_local_pdb_complete.set()
|
||||||
|
|
||||||
# restore original sigint handler
|
# restore original sigint handler
|
||||||
signal.signal(
|
undo_sigint()
|
||||||
signal.SIGINT,
|
|
||||||
orig_handler
|
|
||||||
)
|
|
||||||
|
|
||||||
_pdb_release_hook = teardown
|
_pdb_release_hook = teardown
|
||||||
|
|
||||||
|
@ -664,7 +673,7 @@ def _set_trace(
|
||||||
# last_f = frame.f_back
|
# last_f = frame.f_back
|
||||||
# last_f.f_globals['__tracebackhide__'] = True
|
# last_f.f_globals['__tracebackhide__'] = True
|
||||||
|
|
||||||
if 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(
|
pdb.set_trace(
|
||||||
|
@ -673,15 +682,13 @@ def _set_trace(
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
pdb, undo_sigint = mk_mpdb()
|
||||||
|
|
||||||
# we entered the global ``breakpoint()`` built-in from sync code?
|
# we entered the global ``breakpoint()`` built-in from sync code?
|
||||||
assert 0, 'Woa this path finally triggered?'
|
|
||||||
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'
|
||||||
|
|
||||||
def nuttin():
|
_pdb_release_hook = undo_sigint
|
||||||
pass
|
|
||||||
|
|
||||||
_pdb_release_hook = nuttin
|
|
||||||
|
|
||||||
pdb.set_trace(
|
pdb.set_trace(
|
||||||
# start 2 levels up in user code
|
# start 2 levels up in user code
|
||||||
|
|
Loading…
Reference in New Issue