[paramiko] ctrl-c issue.

Christian Vest Hansen karmazilla at gmail.com
Mon Jan 7 09:56:23 PST 2008


Hi James, thank you for the reply.

> You can also catch the interrupt locally, and call close() on the
> transport (or SSHClient, which in turn calls the transport), which will
> just disconnect you, and the remote program will "probably" just quit.

This apparently dosn't work. We will see no difference if we add the lines:
===========================================
import signal
signal.signal(signal.SIGINT, lambda sig, frame: client.close())
===========================================
To right after where the client obj is instensiated.

I'm thinking the GIL may be blocking us from entering the lambda when
we press ctrl-c.

So, it looks like I'll try dropping to a lower level with the
interactive shell and see if that works - I'm also interrested in the
return codes of my commands so I guess I had to do that anyway. And
then there's the setblocking() which looks handy.


On 1/7/08, James Bardin <jbardin at bu.edu> wrote:
>
>
> Christian Vest Hansen wrote:
> >
> > Steps to reproduce:
> > * connect to some server with normal ssh and $echo a >> my_file
> > * then use above program to connect to the same server and run $tail -f my_file
> > * then $echo b >> my_file and see the tail working
> > * then, in the shell with above program still running, press ctrl-c
> > * notice that pressing ctrl-c dosn't stop above program, regardless of
> > how long you wait
> > * now, in the normal ssh, do $echo c >> my_file
> > * only then will above program notice the term request and halt operation
> >
> > What I want is for the program to terminate immediately when I press
> > ctrl-c, so the question is how I can I make this so?
> >
> >
> >
> Your crtl-c is being sent to the local process, not the remote. The
> local process say "ok, I'll quit when I'm done reading."  The remote
> process doesn't see any of this, so you're sort of in a deadlock.
>
> Ctrl-c is just a SIGINT, so you could send a `kill -2 $PID` along
> another channel to kill the remote process, or use an interactive
> session so the term can send the signals.
>
> You can also catch the interrupt locally, and call close() on the
> transport (or SSHClient, which in turn calls the transport), which will
> just disconnect you, and the remote program will "probably" just quit.
>
>
> -jim
>
>
>
>


-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.



More information about the paramiko mailing list