def start(self, _strXmlInput): """ Launch EDNA with the given XML stream @param _strXmlInput: XML to be passed to the plugin @type _strXmlInput: python string representing the XML data structure """ if (_strXmlInput is None) or (_strXmlInput == "") : return #This is a trick to work-around bug #463: # Run the fist thread alone (delay the second, third, ...) # semaphore._Semaphore__value is the current value of the value, unfortunatly it is a protected value without getter # I need the value of the semaphore to guess if the current call is the first or not. # Nota semaphore are decreased in value from self.__iNbThreads to 0. When Zero, the semaphore is blocking. # Them all other, limited by the semaphore. if self.__bIsFirstExecute: sys.stdout.write("Waiting for first thread to initialize ....") while EDUtilsParallel.getNbRunning() > 0: time.sleep(0.5) sys.stdout.write(".") EDUtilsParallel.semaphoreNbThreadsAcquire() edPlugin = EDParallelExecute.__edFactoryPlugin.loadPlugin(self.__strPluginName) if (edPlugin is not None): edPlugin.setDataInput(_strXmlInput) edPlugin.connectSUCCESS(self.successPluginExecution) edPlugin.connectFAILURE(self.failurePluginExecution) edPlugin.execute() #edPlugin.executeSynchronous() else: EDUtilsParallel.semaphoreNbThreadsRelease() self.__bIsFirstExecute = False EDVerbose.screen("ERROR! Plugin not found : " + self.__strPluginName)
def waitForAllProcessToFinish(self): """ as it names says, this method waits for all plug-ins which are currently running to finish before returning. """ sys.stderr.write("Waiting for launched jobs to finish .") while (EDUtilsParallel.getNbRunning() > 0): time.sleep(1) sys.stderr.write(".") sys.stderr.write("Done.\n")
def join(self): """ wait for all jobs to finish """ while not (self.jobQueue.empty() and \ (self.__semaphoreNbThreads._Semaphore__value == self.iNbCpu) and \ (EDUtilsParallel.getNbRunning() == 0) and \ (self.processingSem._Semaphore__value == 1) and\ (len(EDStatus.getRunning()) == 0)): time.sleep(1)