diff --git a/wetb/hawc2/hawc2_pbsjob.py b/wetb/hawc2/hawc2_pbsjob.py new file mode 100644 index 0000000000000000000000000000000000000000..3b5401fe80e3fb1ca31a35536bddcdf99293345c --- /dev/null +++ b/wetb/hawc2/hawc2_pbsjob.py @@ -0,0 +1,64 @@ + + +from wetb.hawc2.htc_file import HTCFile +from wetb.utils.cluster_tools.pbsjob import PBSJob +from wetb.hawc2.log_file import LogInterpreter +import os +import time +from wetb.utils.cluster_tools import pbsjob +class HAWC2PBSJob(PBSJob): + + def __init__(self, host, username, password): + PBSJob.__init__(self, host, username, password) + + + def submit(self, job, cwd, pbs_out_file): + with open (cwd + job) as fid: + htcfilename = [l for l in fid if l.startswith('wine')][0].rsplit(" ", 1)[1].strip() + print (htcfilename) + htcfile = HTCFile(cwd + htcfilename) + + logfilename = htcfile.simulation.logfile[0] + self.loginterpreter = LogInterpreter(htcfile.simulation.time_stop[0]) + print (self.loginterpreter.filename) + PBSJob.submit(self, job, cwd, pbs_out_file) + + def status_monitor(self, update=5): + i = 0 + self.loglinenumber = 0 + while self.in_queue(): + i += 1 + print (i, self.status, self.get_nodeid()) + if self.status is pbsjob.RUNNING: + #self.test() + scratch_log_filename = "/scratch/%s/%s.g-000.risoe.dk/%s" % (self.client.username, self.jobid, self.loginterpreter.filename) + try: + n, out, err = self.client.execute('tail --lines=+%d %s' % (self.loglinenumber, scratch_log_filename)) + self.loginterpreter.update_status(out) + print (self.loginterpreter.status, self.loginterpreter.pct, self.loginterpreter.remaining_time, self.loginterpreter.lastline) + with open("status" + self.jobid, 'w') as fid: + fid.write(";".join([self.loginterpreter.status, str(self.loginterpreter.pct), str(self.loginterpreter.remaining_time), self.loginterpreter.lastline])) + #print (out) + self.loglinenumber += out.count ("\n") + #print (err) + + except Warning as e: + if not "tail: cannot open" in str(e): + print (str(e)) + + time.sleep(update) + print (i, self.status, self.get_nodeid()) + + def test(self): + self.log_filename = "logfiles/short.log" + scratch_log_filename = "/scratch/%s/%s.g-000.risoe.dk/%s" % (self.client.username, self.jobid, self.log_filename) + print (scratch_log_filename) + try: + n, out, err = self.client.execute('tail --lines=+%d %s' % (self.loglinenumber, scratch_log_filename)) + print (n) + print (out) + self.loglinenumber += out.count ("\n") + print (err) + + except Warning as e: + print (str(e)) diff --git a/wetb/hawc2/log_file.py b/wetb/hawc2/log_file.py index 622bb6fc009df5834ecf6ab9f2ee3bfe26be5748..9e8d465398ef2f1d033a8a1ff06731aa28537725 100644 --- a/wetb/hawc2/log_file.py +++ b/wetb/hawc2/log_file.py @@ -70,7 +70,7 @@ class LogInterpreter(object): if self.status == UNKNOWN or self.status == MISSING: self.status = PENDING txt = new_lines - self.txt += txt + sself.txt += txt if self.status == PENDING and self.position > 0: self.status = INITIALIZATION