# SVN changeset patch # User imanay # Date 2013-05-15 22:50:28.522920 # Revision 172 starting with threads. Index: trunk/absroot/source/abspy/bin/server3.py =================================================================== diff --git a/trunk/absroot/source/abspy/bin/server3.py b/trunk/absroot/source/abspy/bin/server3.py --- a/trunk/absroot/source/abspy/bin/server3.py (revision 171) +++ b/trunk/absroot/source/abspy/bin/server3.py (revision 172) @@ -1,7 +1,9 @@ import os import library3 import time +from threading import Thread import threading +import Queue class ABSServer: @@ -26,8 +28,8 @@ self.createObjects() print "Checking control modules, please wait ..." -# self.enaModules = self.checkAntenna() - self.enaModules = [1,12] + self.enaModules = self.checkAntenna() +# self.enaModules = [1,12] print "Starting automatic control module status." self.__StartingAutomaticControlModules() self.__AutomaticControlModules() @@ -68,7 +70,7 @@ self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource) - def checkModule(self, address): + def __checkModule(self, address): cmd = "ping -c 1 -w 1 192.168.1."+ str(address) + " >> /dev/null" status = os.system(cmd) @@ -113,7 +115,7 @@ fobj.writelines(data) fobj.close() - def checkAntenna(self): + def __checkAntenna(self): """ Direccion de los modulos de las antenas: @@ -133,6 +135,40 @@ self.__writeReport(enaModules2) return enaModules2 + + def checkModule(self, arg, queue): + cmd = "ping -c 1 -w 1 192.168.1."+ str(arg) + " >> /dev/null" + status = os.system(cmd) + if status == 256: + result = "failed" + else: + result = "ok" + queue.put({arg: result}) + + def checkAntenna(self): + + iD = range(1,256) + q = Queue.Queue() + threads = [] + tOut = [] + modules = [] + + for argument in iD: + t = Thread(target=self.checkModule, args=(argument, q)) + t.start() + threads.append(t) + + for t in threads: + t.join() + + for _ in range(len(iD)): + tOut.append(q.get()) + + for i in tOut: + if i.values()[0] == 'ok': + modules.append(i.keys()[0]) + + return modules def __ConnectionWithControlModules(self,data,cmd,id):