[Twisted-Python] sending 'tail -f' command to a remote host using conch?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Aug 10 09:29:25 EDT 2009

On 06:10 am, nharsha at gmail.com wrote:
>Hi All,
>A day back I install Twisted and Conch on RHEL5. I am a novice user of
>Twisted software.
>I copied an example from dev-shed website (attached herewith). This 
>script uses conch to talk to a ssh deamon.
>This script was able to capture and return the output of simple 
>such as - ls, cat etc.
>I mean, when I run the script to execute 'ls -al' on a remote machine 
>does and returns the prompt.
>Where as, when I run the script to execute '*tail -f 
>/path/to/mylog.txt*' I
>get the ouput of this command but the prompt never returns.
>When I press ^C (Control-C) I get the following run-time error.
>  File "shankha.py", line 56, in closed
>    reactor.stop()
>  File
>line 526, in stop
>    raise error.ReactorNotRunning(
>twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't

This happens because your program tries to stop the reactor twice. 
First, it tries to stop it when you hit ^C - the default handing of ^C 
is to stop the reactor.  Then, your SSH connection is closed (because 
all connections are closed when the reactor is stopped).  Your code 
handles this by calling reactor.stop() again.
>*I know that 'tail -f' command is expecting "Control-C" or Break to 
>the prompt on remote host.
>But my attempt to send the ^C character is failing..
>I am doing somethink like this:
>python sshc.py <hostname> 'tail -f mylog.txt ; \x03'
>What is the recommended method to adopt such cases?

You need to set up some glue.  Right now, ^C is not being sent to the 
remote process at all.  It's only being sent to your local sshc.py 
process.  You may want to install your own SIGINT handler, or you may 
want to add a before shutdown trigger (or use a service's stopService 
method) to send ^C to the remote process.  As to what the Conch API is 
for sending a signal to a process, I'm not sure.


More information about the Twisted-Python mailing list