Ejemplo n.º 1
0
class Worker(threading.Thread):
    """
    A Worker is a deamonic thread, that takes jobs from the workingQueue and runs them.
    """
    workingQueue = Queue.Queue()

    def __init__(self, number, outputHandler):
        threading.Thread.__init__(self) # constuctor of superclass
        self.numberOfThread = number
        self.outputHandler = outputHandler
        self.runExecutor = RunExecutor()
        self.setDaemon(True)
        self.start()

    def run(self):
        while not Worker.workingQueue.empty() and not STOPPED_BY_INTERRUPT:
            currentRun = Worker.workingQueue.get_nowait()
            try:
                self.execute(currentRun)
            except BaseException as e:
                print(e)
            Worker.workingQueue.task_done()


    def execute(self, run):
        """
        This function executes the tool with a sourcefile with options.
        It also calls functions for output before and after the run.
        """
        self.outputHandler.outputBeforeRun(run)

        (run.wallTime, run.cpuTime, run.memUsage, returnvalue, output) = \
            self.runExecutor.executeRun(
                run.getCmdline(), run.benchmark.rlimits, run.logFile,
                myCpuIndex=self.numberOfThread,
                environments=run.benchmark.getEnvironments(),
                runningDir=run.benchmark.workingDirectory(),
                maxLogfileSize=config.maxLogfileSize)

        if self.runExecutor.PROCESS_KILLED:
            # If the run was interrupted, we ignore the result and cleanup.
            run.wallTime = 0
            run.cpuTime = 0
            try:
                if config.debug:
                   os.rename(run.logFile, run.logFile + ".killed")
                else:
                   os.remove(run.logFile)
            except OSError:
                pass
            return

        run.afterExecution(returnvalue, output)
        self.outputHandler.outputAfterRun(run)


    def stop(self):
        # asynchronous call to runexecutor, 
        # the worker will stop asap, but not within this method.
        self.runExecutor.kill()
Ejemplo n.º 2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

        #sys.stderr.write(str(argv)+"\n")

    if len(argv) >= 5 and len(argv) <=6:


        rlimits={}

        data = eval(argv[1]) # arg[1] is a string-representation of a data-structure
        args = data.get("args", [])
        env = data.get("env", {})
        debugEnabled = data.get("debug", False)
        logfileSize = data.get("maxLogfileSize", 20) # MB

        if debugEnabled:
            logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s",
                            level=logging.DEBUG)
        else:
            logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s")

        if not (argv[2]=="-1" or argv[2]=="None"):
            rlimits[MEMLIMIT] = int(argv[2])
        rlimits[TIMELIMIT] = int(argv[3])
        outputFileName = argv[4]
        if(len(argv) == 6):
             rlimits[CORELIMIT] = int(argv[5])

        global runExecutor
        runExecutor = RunExecutor()

        logging.debug("runExecutor.executeRun() started.")

        (wallTime, cpuTime, memUsage, returnvalue, output) = \
            runExecutor.executeRun(args, rlimits, outputFileName, environments=env, maxLogfileSize=logfileSize);

        logging.debug("runExecutor.executeRun() ended.")

        print("Walltime: " + str(wallTime))
        print("CpuTime: " + str(cpuTime))
        print("MemoryUsage: " + str(memUsage))
        print("Returnvalue: " + str(returnvalue))

        return returnvalue

    else:
        sys.exit("Wrong number of arguments, expected exactly 4 or 5: <command> <memlimit in MB> <timelimit in s> <output file name> <core limit(optional)>")
Ejemplo n.º 3
0
 def __init__(self, number, outputHandler):
     threading.Thread.__init__(self) # constuctor of superclass
     self.numberOfThread = number
     self.outputHandler = outputHandler
     self.runExecutor = RunExecutor()
     self.setDaemon(True)
     self.start()