diff --git a/tractor/_spawn.py b/tractor/_spawn.py index c7eb2d2..ac5bb5a 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -366,7 +366,9 @@ async def new_proc( await proc.wait() if is_root_process(): - await maybe_wait_for_debugger() + await maybe_wait_for_debugger( + child_in_debug=_runtime_vars.get('_debug_mode', False), + ) if proc.poll() is None: log.cancel(f"Attempting to hard kill {proc}") diff --git a/tractor/_supervise.py b/tractor/_supervise.py index ea0ecfa..ae224a8 100644 --- a/tractor/_supervise.py +++ b/tractor/_supervise.py @@ -50,6 +50,7 @@ class ActorNursery: self._cancel_after_result_on_exit: set = set() self.cancelled: bool = False self._join_procs = trio.Event() + self._at_least_one_child_in_debug: bool = False self.errors = errors self.exited = trio.Event() @@ -64,6 +65,11 @@ class ActorNursery: nursery: trio.Nursery = None, debug_mode: Optional[bool] = None, ) -> Portal: + ''' + Start a (daemon) actor: an process that has no designated + "main task" besides the runtime. + + ''' loglevel = loglevel or self._actor.loglevel or get_loglevel() # configure and pass runtime state @@ -73,6 +79,7 @@ class ActorNursery: # allow setting debug policy per actor if debug_mode is not None: _rtv['_debug_mode'] = debug_mode + self._at_least_one_child_in_debug = True enable_modules = enable_modules or [] @@ -287,7 +294,9 @@ async def _open_and_supervise_one_cancels_all_nursery( # will make the pdb repl unusable. # Instead try to wait for pdb to be released before # tearing down. - await maybe_wait_for_debugger() + await maybe_wait_for_debugger( + child_in_debug=anursery._at_least_one_child_in_debug + ) # if the caller's scope errored then we activate our # one-cancels-all supervisor strategy (don't @@ -341,6 +350,9 @@ async def _open_and_supervise_one_cancels_all_nursery( ) as err: + await maybe_wait_for_debugger( + child_in_debug=anursery._at_least_one_child_in_debug + ) # If actor-local error was raised while waiting on # ".run_in_actor()" actors then we also want to cancel all # remaining sub-actors (due to our lone strategy: