I am running an interactive ssh python program, but I'm not always technically interacting with it (piping stdout and stdin). I need to print a string to signal to pexpect on my local machine that a breakpoint has been called and to enter interactive mode.
On my local machine I have:
p: pexpect.spawn
i = p.expect([pexpect.EOF,'__INTERACT__'])
if i==1:
p.interact()
The reason I do this is because I cannot simply interact() the whole time it is running. This interferes with stdout on the local process.
So on the remote process, I breakpoint with
print('__INTERACT__')
breakpoint()
This works, however I want to have single-line breakpoints. So I tried:
def remote_breakpoint():
print('__INTERACT__')
import pdb; pdb.set_trace()
sys.breakpointhook = remote_breakpoint
This allows me to just write breakpoint(). It's also allows me to disable the extra print statement when running locally:
def remote_breakpoint():
if platform.system() != 'Darwin':
print('__INTERACT__')
import pdb; pdb.set_trace()
It works, But now pdb starts inside the remote_breakpoint function and I have to hit r to get out every time. How can I tell pdb.set_trace to start one function up the stack, or make it wait to start the interactive process until remote_breakpoint has returned?
Even if I just call remote_breakpoint() (instead of using sys.breakpointhook), I still have the same problem.