Skip to content
Snippets Groups Projects
cluster_simulation.py 1.1 KiB
Newer Older
from wetb.hawc2.simulation import Simulation
mads's avatar
mads committed
import os
mads's avatar
mads committed
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"):
        Simulation.__init__(self, modelpath, htcfilename, hawc2exe=hawc2exe)
mads's avatar
mads committed

mads's avatar
mads committed
        self.simulation_id = [f for f in os.listdir('.') if f.endswith('.in')][0][:-3]
mads's avatar
mads committed
        self.host.simulationThread.low_priority = False
        self.non_blocking_simulation_thread = Thread(target=self.simulate)
mads's avatar
mads committed
        self.start(1)
        self.wait()
        self.is_done = True
mads's avatar
mads committed
        print (self.host.simulationThread.res[1])  # print hawc2 output to stdout
        sys.exit(self.host.simulationThread.res[0])
mads's avatar
mads committed

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

    def show_status(self):
        pass