Esempio n. 1
0
    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)
Esempio n. 2
0
 def finallyProcess(self, _edObject=None):
     """
     after processing of the plugin:
     Release a CPU resource by releasing the semaphore
     """
     EDVerbose.DEBUG("Release semaphore nbCPU by plugin %s, currently value: %s" % (self.getPluginName(), EDUtilsParallel.getSemaphoreValue()))
     EDUtilsParallel.semaphoreNbThreadsRelease()
     EDPlugin.finallyProcess(self, _edObject)
Esempio n. 3
0
 def finallyProcess(self, _edObject=None):
     """
     after processing of the plugin:
     Release a CPU resource by releasing the semaphore
     """
     self.DEBUG("Release semaphore nbCPU by plugin %s" % self.getPluginName())
     EDUtilsParallel.semaphoreNbThreadsRelease()
     EDPlugin.finallyProcess(self, _edObject)
Esempio n. 4
0
 def finallyProcess(self, _edObject=None):
     """
     after processing of the plugin:
     Release a CPU resource by releasing the semaphore
     """
     EDVerbose.DEBUG(
         "Release semaphore nbCPU by plugin %s, currently value: %s" %
         (self.getPluginName(), EDUtilsParallel.getSemaphoreValue()))
     EDUtilsParallel.semaphoreNbThreadsRelease()
     EDPlugin.finallyProcess(self, _edObject)
Esempio n. 5
0
 def cleanUp(self, _edPlugin):
     """
     Cleans up some empty directories 
     (mainly working directories that were created automatically, but not filled as Unit tests do not execute the plugin)
     """
     workingDirectory = _edPlugin.getWorkingDirectory()
     if(workingDirectory is not None):
         fileList = glob.glob(os.path.join(workingDirectory, "*"))
         if(len(fileList) == 0):
             EDVerbose.DEBUG("Deleting " + workingDirectory + " ...")
             shutil.rmtree(workingDirectory)
     EDUtilsParallel.semaphoreNbThreadsRelease()
Esempio n. 6
0
 def cleanUp(self, _edPlugin):
     """
     Cleans up some empty directories 
     (mainly working directories that were created automatically, but not filled as Unit tests do not execute the plugin)
     """
     workingDirectory = _edPlugin.getWorkingDirectory()
     if (workingDirectory is not None):
         fileList = glob.glob(os.path.join(workingDirectory, "*"))
         if (len(fileList) == 0):
             EDVerbose.DEBUG("Deleting " + workingDirectory + " ...")
             shutil.rmtree(workingDirectory)
     EDUtilsParallel.semaphoreNbThreadsRelease()
Esempio n. 7
0
 def failurePluginExecution(self, _edObject=None):
     """
     Method called when the execution of the plugin failed 
     """
     EDUtilsParallel.semaphoreNbThreadsRelease()
     self.__bIsFirstExecute = False
     if self.__functXMLerr is None:
         EDVerbose.screen("Plugin %s execution ended with failure" % self.__strPluginName)
     else:
         self.__semaphoreErr.acquire()
         self.__functXMLerr(_edObject.dataInput.marshal())
         self.__semaphoreErr.release()
Esempio n. 8
0
 def successPluginExecution(self, _edObject=None):
     """
     Method called when the execution of the plugin succeeds 
     """
     EDUtilsParallel.semaphoreNbThreadsRelease()
     self.__bIsFirstExecute = False
     if self.__functXMLout is None:
         EDVerbose.screen("Plugin %s execution ended with success" % self.__strPluginName)
     else:
         self.__semaphoreOut.acquire()
         self.__functXMLout(_edObject.dataInput.marshal(), _edObject.getDataOutput().marshal())
         self.__semaphoreOut.release()
Esempio n. 9
0
 def semaphoreNbThreadsRelease(self):
     """Method to release the semaphore that controls the number of threads running concurrently"""
     EDUtilsParallel.semaphoreNbThreadsRelease()
Esempio n. 10
0
 def semaphoreNbThreadsRelease(self):
     """Method to release the semaphore that controls the number of threads running concurrently"""
     EDUtilsParallel.semaphoreNbThreadsRelease()