example of multi threads

Sandy dksreddy at gmail.com
Thu Jun 24 04:23:33 EDT 2010


On Jun 23, 11:58 am, Stefan Behnel <stefan... at 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



More information about the Python-list mailing list