From e4ed0fd2b3ef7898b9e056685c0a2486e89fefba Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 15 Oct 2021 09:29:25 -0400 Subject: [PATCH] Right, only worry about pdb lock when in debug mode --- tractor/_debug.py | 6 +++--- tractor/_spawn.py | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tractor/_debug.py b/tractor/_debug.py index 8a0d414..67485af 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -21,7 +21,7 @@ from trio_typing import TaskStatus from .log import get_logger from . import _state from ._discovery import get_root -from ._state import is_root_process +from ._state import is_root_process, debug_mode from ._exceptions import is_multi_cancelled try: @@ -525,7 +525,7 @@ post_mortem = partial( async def _maybe_enter_pm(err): if ( - _state.debug_mode() + debug_mode() # NOTE: don't enter debug mode recursively after quitting pdb # Iow, don't re-enter the repl if the `quit` command was issued @@ -572,7 +572,7 @@ async def maybe_wait_for_debugger( poll_delay: float = 0.1, ) -> None: - if not _state.debug_mode(): + if not debug_mode(): return if ( diff --git a/tractor/_spawn.py b/tractor/_spawn.py index 4f496e4..1f22310 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -30,6 +30,7 @@ from ._state import ( current_actor, is_main_process, is_root_process, + debug_mode, ) from .log import get_logger @@ -242,17 +243,19 @@ async def new_proc( subactor.uid) except trio.Cancelled: cancel_during_spawn = True + # we may cancel before the child connects back in which # case avoid clobbering the pdb tty. - with trio.CancelScope(shield=True): - # don't clobber an ongoing pdb - if is_root_process(): - await maybe_wait_for_debugger() - else: - async with acquire_debug_lock(uid): - # soft wait on the proc to terminate - with trio.move_on_after(0.5): - await proc.wait() + if debug_mode(): + with trio.CancelScope(shield=True): + # don't clobber an ongoing pdb + if is_root_process(): + await maybe_wait_for_debugger() + else: + async with acquire_debug_lock(uid): + # soft wait on the proc to terminate + with trio.move_on_after(0.5): + await proc.wait() raise portal = Portal(chan) @@ -312,9 +315,8 @@ async def new_proc( # don't clobber an ongoing pdb await maybe_wait_for_debugger() - if cancel_during_spawn: - - # Try again to avoid TTY clobbering. + # Try again to avoid TTY clobbering. + if cancel_during_spawn and debug_mode(): async with acquire_debug_lock(uid): with trio.move_on_after(0.5): await proc.wait()