[Twisted-Python] Conch: multiple commands

Brendan Simon Brendan at BrendanSimon.com
Thu Feb 9 07:37:11 EST 2006


I'm trying to use and understand the latest Twisted and Conch (I'm a 
newbie).  I can get teh sample apps going fine but they all seem to send 
one command and then exit.  I'm trying to workout how to send multiple 
commands to the server from the same client application.

The sshsimpleclient.py does send multiple commands (false, true, cat) 
with separate channels.
Is that the preferred way to send multiple commands?
Doesn't that require some setup overhead every time I want to issue a 
command to the server?

Is it possible to open _one_ channel, and send commands in a 
synchronously?  ie. wait for commands to return output and then issue 
other commands if necesary??
Maybe this goes against the grain of the Twisted Asynchronous Framework ???

If I assume that I have to open a new channel for each command, and I 
have a 100 different commands, I could have 100 classes for each command 
(seems a bit extreme) or have one class that gets the command passed to 
it.  The problem I see with the latter is that I don't know how to wait 
until the first command has got a reply and is finished.  It seems that 
the channelOpen method returns straight away.  How can I control the 
program execution to wait for the response, error or timeout?  Example:
    def servicesStarted(self):
        self.openChannel(CommandChannel.openChannel('ls /tmp/dir1')
        # how do I wait for list of dir1 to finish?
        self.openChannel(CommandChannel.openChannel('ls /tmp/dir2')
        # how do I wait for list of dir2 to finish?
        self.openChannel(CommandChannel.openChannel('ls /tmp/dir3')
        # how do I wait for list of dir3 to finish?

Thanks,
Brendan.





More information about the Twisted-Python mailing list