From 7886a9fa64bd8ebe2039e0441f69008122482a8d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 24 Jul 2020 15:15:52 -0400 Subject: [PATCH] Try ipdb to get tab-complete without a tty It doesn't work but in theory since ipython uses python-prompt-toolkit this may be possible (and is really the best solution over trying to hack ttys/ptys in the child). If `ipdb` is installed try using it. --- tractor/_debug.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tractor/_debug.py b/tractor/_debug.py index f4edf43..294b094 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -97,6 +97,12 @@ def _breakpoint(debug_func) -> Awaitable[None]: in subactors. """ actor = tractor.current_actor() + try: + import ipdb + db = ipdb + except ImportError: + import pdb + db = pdb async def wait_for_parent_stdin_hijack(): log.debug('Breakpoint engaged!') @@ -116,14 +122,14 @@ def _breakpoint(debug_func) -> Awaitable[None]: # block here one frame up where ``breakpoint()`` # was awaited and begin handling stdin - debug_func(actor) + debug_func(actor, db) # this must be awaited by caller return wait_for_parent_stdin_hijack() -def _set_trace(actor): - pdb.set_trace( +def _set_trace(actor, dbmod): + dbmod.set_trace( header=f"\nAttaching pdb to actor: {actor.uid}\n", # start 2 levels up frame=sys._getframe().f_back.f_back, @@ -136,9 +142,10 @@ breakpoint = partial( ) -def _post_mortem(actor): - log.error(f"\nAttaching to pdb in crashed actor: {actor.uid}\n") - pdb.post_mortem() +def _post_mortem(actor, dbmod): + log.error( + f"\nAttaching to {dbmod} in crashed actor: {actor.uid}\n") + dbmod.post_mortem() post_mortem = partial(