python-remote-pdb icon indicating copy to clipboard operation
python-remote-pdb copied to clipboard

How I can send SIGINT over a telnet session?

Open Kentzo opened this issue 10 years ago • 9 comments

I want to break the execution of the script by sending SIGINT. Something like typing Ctrl-C or Ctrl-] send brk do not work.

Kentzo avatar Oct 16 '15 05:10 Kentzo

Not sure I understand what you want to accomplish. Can you elaborate?

If you want to send sigint to current process you'd do something like os.kill(os.getpid(), signal.SIGINT) but I doubt that's what you need.

ionelmc avatar Oct 16 '15 07:10 ionelmc

@ionelmc PDB allows you to inject set_trace by receiving the SIGINT signal.

One way to send SIGINT is by doing this on the local system (e.g. via kill or from python). But how can I achieve this remotely?

Kentzo avatar Oct 17 '15 16:10 Kentzo

AFAIK you can't. Unless you make some sort of contraption to deliver the signal from a remote machine. Or you forcefully attach a pty to the process (good luck with that).

I might have different ideas if you explain a bit what sort of problem you want to solve or what you want to achieve with this.

ionelmc avatar Oct 17 '15 17:10 ionelmc

Well, it's pretty obvious what I want to achieve: being able to break execution at arbitrary point without having direct access to the remote machine :)

One solution would be to spawn a process from remote_pdb, and interpret input via telnet to ask that process to send SIGINT.

Kentzo avatar Oct 17 '15 17:10 Kentzo

You could use https://github.com/ionelmc/python-manhole + ssh

Also check out https://github.com/ionelmc/python-manhole#similar-projects

remote-pdb doesn't have anything that does what you want.

ionelmc avatar Oct 17 '15 17:10 ionelmc

@ionelmc I need this on Windows as well :(

Kentzo avatar Oct 17 '15 17:10 Kentzo

Then you need to run some sort of daemon in a thread. :grimacing:

This looks like what you need: https://bitbucket.org/xdegaye/pdb-clone/wiki/RemoteDebugging.md

remote-pdb is very very simple. Let me know how pdb-clone works.

ionelmc avatar Oct 17 '15 18:10 ionelmc

Sure. Right now I'm struggle another problem, but that's rather related to pythons internals :)

Kentzo avatar Oct 18 '15 02:10 Kentzo

@ionelmc I figured out what @Kentzo was trying to do if you hadn't actually figured out what they were trying to do.

In Python 3 you'll see they added handling for SIGINT in the pdb module. I had to look a little to figure out how that actually worked and what it was doing. It looks like if you type "continue" at the prompt you were then allowed to sent the interrupt signal to stop the debugger where you were at that time.

See: continue and the handler

I haven't had a chance to look at the source for this package yet, but I think what they were expecting was that you registered a signal handler when running continue (as pdb does), which maybe is happening since this package is very likely just driving pdb, and they were just looking for a way to invoke that functionality.

So they are indeed looking for a way to send Ctrl+C to the same process. I also found the following when poking around. Which is basically the same thing and steered me to just look at the Python source to see what was happening on their end (roughly the same thing).

I'm not sure if the remote server is still listening or is started in a thread, but the only way to support this functionality would be to periodically check the socket for either a Ctrl+C over the socket or some other bit of data that might be easier for something like nc to send. If neither of these are possible this should be closed as a "won't fix" and maybe a quick comment in the documentation would be appropriate and if this package is indeed just driving pdb it probably should disable the signal handler in case it gets in the way of something else.

terencehonles avatar Jul 24 '20 19:07 terencehonles