Skip to content
Snippets Groups Projects
cluster_simulation.py 1.06 KiB
Newer Older
mads's avatar
mads committed
from wetb.hawc2.simulation import Simulation, SimulationThread
mads's avatar
mads committed
import os
import sys
mads's avatar
mads committed
from threading import  Thread
mads's avatar
mads committed
class ClusterSimulation(Simulation):
    def __init__(self, modelpath, htcfilename, hawc2exe="HAWC2MB.exe"):
mads's avatar
mads committed
        print ("start")
mads's avatar
mads committed
        Simulation.__init__(self, modelpath, htcfilename, hawc2exe=hawc2exe)
        self.simulation_id = [f for f in os.listdir('.') if f.endswith('.in')][0][:-3]
mads's avatar
mads committed
        self.resource.simulationThread.low_priority = False
mads's avatar
mads committed
        self.thread = Thread(target=self.simulate)
        self.start(1)
        self.wait()
mads's avatar
mads committed
        print (self.resource.simulationThread.res[1])  # print hawc2 output to stdout
        sys.exit(self.resource.simulationThread.res[0])
mads's avatar
mads committed

    def update_status(self, *args, **kwargs):
        Simulation.update_status(self, *args, **kwargs)
        with open("/home/mmpe/.hawc2launcher/status_%s" % self.simulation_id, 'w') as fid:
            fid.write (";".join([self.status] + [str(getattr(self.logFile, v)) for v in ['status', 'pct', 'remaining_time', 'lastline']]) + "\n")

    def show_status(self):
        pass