Beispiel #1
0
    daemonize(
        stdout=os.path.join(configuration.TASK_DIR, "%s.out" % iui),
        stderr=os.path.join(configuration.TASK_DIR, "%s.err" % iui),
    )

    db.open()  # Open again after daemonizing
    try:
        task = Task(db, iui=iui)
        try:
            tool = configuration.TOOLS_LOOKUP[task.tool]
        except KeyError:
            raise ValueError("no such tool '%s'" % task.tool)

        # The tool must save the pid of the process doing the heavy work.
        tool(task)

        task.cpu_time = 0.0
        for who in (resource.RUSAGE_SELF, resource.RUSAGE_CHILDREN):
            usage = resource.getrusage(who)
            task.cpu_time += usage.ru_utime + usage.ru_stime
    except Exception, msg:
        task.data["error"] = "%s\n%s" % (task.data.get("error", ""), msg)
        task._status = configuration.FAILED
    finally:
        task.save()
        db.close()


if __name__ == "__main__":
    execute()