From a2151cdd4d4091e60db49b7fef612677141f5102 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 4 Oct 2020 09:55:34 -0400 Subject: [PATCH] Allow re-entrant breakpoints during pdb stepping --- tractor/_debug.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tractor/_debug.py b/tractor/_debug.py index b9ed5a2..a0a5fc6 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -180,7 +180,6 @@ def _breakpoint(debug_func) -> Awaitable[None]: """``tractor`` breakpoint entry for engaging pdb machinery in subactors. """ - global _in_debug actor = tractor.current_actor() do_unlock = trio.Event() @@ -196,7 +195,7 @@ def _breakpoint(debug_func) -> Awaitable[None]: start_msg_loop=False, # shield=True, ) as portal: - with trio.fail_after(1): + with trio.fail_after(.5): agen = await portal.run( 'tractor._debug', '_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 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 # waiting for the control to be released - this allows # 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 # entries/requests to the root process - _in_debug = True + _in_debug = task_name # TODO: need a more robust check for the "root" actor if actor._parent_chan: