From: Mag Gam on
I am looking for a simple multi threaded example.

Lets say I have to ssh to 20 servers and I would like to that in
parallel. Can someone please provide a an example for that?

thanks
From: Stefan Behnel on
Mag Gam, 23.06.2010 12:24:
> I am looking for a simple multi threaded example.
>
> Lets say I have to ssh to 20 servers and I would like to that in
> parallel. Can someone please provide a an example for that?

Sounds like you want to run background processes, not threads. Take a look
at the subprocess module.

Stefan

From: Sandy on
On Jun 23, 11:58 am, Stefan Behnel <stefan...(a)behnel.de> wrote:
> Mag Gam, 23.06.2010 12:24:
>
> > I am looking for a simple multi threaded  example.
>
> > Lets say I have to ssh to 20 servers and I would like to that in
> > parallel. Can someone please provide a an example for that?
>
> Sounds like you want to run background processes, not threads. Take a look
> at the subprocess module.
>
> Stefan

I use ssh which in turn uses paramiko

import os
import ssh
for i in xrange(len(tasks)):
pid = os.fork()
if pid == 0:
# if child process
s = ssh.Connection(host = server, log =
False)
s.execute(cmd)
s.close()
os._exit(0)
time.sleep(1)

os.waitpid(pid, 0)

- dksr