Hi Folks! I'd like to create a web application that will basically send a command to 1000 servers and grab some data using subprocess + ssh like:
*p = sub.Popen(['ssh','-q', 'support@%s'%hostname, command],stdout=sub.PIPE, stderr=sub.STDOUT) out = p.stdout.read() print out # it will be a db insert p.poll() rc=p.returncode print rc # it will be a db insert* I can't execute all threads at the same time so I would need to pool then and execute using Queue module. My first code was:* class ThreadSSH(threading.Thread): """Thread ssh command""" def __init__(self, queue, name): threading.Thread.__init__(self) self.queue = queue self.name = name def run(self): #while not self.queue.empty(): while True: # print 'Starting %s' %self.name #grabs host from queue print 'Empty: %s' %self.queue.empty() print 'Qsize: %s' %self.queue.qsize() print '%s' %dir(self.queue) host = self.queue.get() #core of the thread time.sleep(10) print 'Active count: %s' %threading.activeCount() print "Exiting " + self.name #signals to queue job is done self.queue.task_done() def test(): hosts = ['host1', 'host2', 'host3', 'host4'] # Queue of servers, we will fill it down there queue = Queue.Queue() print 'begin: %s' %threading.enumerate() #spawn a pool of threads, and pass them queue instance for i in range(20): t = ThreadSSH(queue, 'test-%s' %i) t.setDaemon(True) t.start() print 'thread generated: %s' %threading.enumerate() #populate queue with data for host in hosts: queue.put(host) print 'SIZE: %s' %queue.qsize()* Not sure if this is the right approach for this kind of application but the problem is that those threads never ends... if I put in another function: *def threadInfo(): output='enumerate: %s<br/>' %['%s Live(%s) Daemon(%s)' %(t.name,t.isAlive(),t.isDaemon()) for t in threading.enumerate()] output+='active count: %s<br/>' %threading.activeCount() output+='current thread: %s<br/>' %threading.currentThread().name return output* I can see that even the thread ending it is showing on enumerate. Do you guys have another idea or know how to fix this issue? Thanks in advance, Tito -- Linux User #387870 .........____ .... _/_õ|__| ..º[ .-.___.-._| . . . . .__( o)__( o).:_______ --