Allow re-entrant breakpoints during pdb stepping

debug_tests
Tyler Goodlet 2020-10-04 09:55:34 -04:00
parent 73a32f7d9c
commit a2151cdd4d
1 changed files with 10 additions and 5 deletions

View File

@ -180,7 +180,6 @@ def _breakpoint(debug_func) -> Awaitable[None]:
"""``tractor`` breakpoint entry for engaging pdb machinery """``tractor`` breakpoint entry for engaging pdb machinery
in subactors. in subactors.
""" """
global _in_debug
actor = tractor.current_actor() actor = tractor.current_actor()
do_unlock = trio.Event() do_unlock = trio.Event()
@ -196,7 +195,7 @@ def _breakpoint(debug_func) -> Awaitable[None]:
start_msg_loop=False, start_msg_loop=False,
# shield=True, # shield=True,
) as portal: ) as portal:
with trio.fail_after(1): with trio.fail_after(.5):
agen = await portal.run( agen = await portal.run(
'tractor._debug', 'tractor._debug',
'_hijack_stdin_relay_to_child', '_hijack_stdin_relay_to_child',
@ -225,9 +224,15 @@ def _breakpoint(debug_func) -> Awaitable[None]:
"""Async breakpoint which schedules a parent stdio lock, and once complete """Async breakpoint which schedules a parent stdio lock, and once complete
enters the ``pdbpp`` debugging console. enters the ``pdbpp`` debugging console.
""" """
global _in_debug task_name = trio.lowlevel.current_task()
global _in_debug
if _in_debug :
if _in_debug == task_name:
# this task already has the lock and is
# likely recurrently entering a breakpoint
return
if _in_debug:
# if **this** actor is already in debug mode block here # if **this** actor is already in debug mode block here
# waiting for the control to be released - this allows # waiting for the control to be released - this allows
# support for recursive entries to `tractor.breakpoint()` # support for recursive entries to `tractor.breakpoint()`
@ -242,7 +247,7 @@ def _breakpoint(debug_func) -> Awaitable[None]:
# mark local actor as "in debug mode" to avoid recurrent # mark local actor as "in debug mode" to avoid recurrent
# entries/requests to the root process # entries/requests to the root process
_in_debug = True _in_debug = task_name
# TODO: need a more robust check for the "root" actor # TODO: need a more robust check for the "root" actor
if actor._parent_chan: if actor._parent_chan: