| | |
| | | import psutil |
| | | import time |
| | | import datetime |
| | | |
| | | import subprocess |
| | | |
| | | # Process status |
| | | TS_NOLOCK=0 # lock file does not exist |
| | |
| | | ''' |
| | | Class Runner consists of a single running or terminated instance of the trisurf. It manages starting, stopping, verifying the running process and printing the reports of the configured instances. |
| | | ''' |
| | | def __init__(self, subdir='run0', tape='', snapshot=''): |
| | | def __init__(self, subdir='run0', tape='', snapshot='', runArgs=[]): |
| | | self.subdir=subdir |
| | | self.runArgs=runArgs |
| | | self.fromSnapshot=False |
| | | if(tape!=''): |
| | | self.initFromTape(tape) |
| | | if(snapshot!=''): |
| | |
| | | except: |
| | | print("Error reading snapshot file") |
| | | exit(1) |
| | | |
| | | self.fromSnapshot=True |
| | | self.snapshotFile=snapshotfile |
| | | root = tree.getroot() |
| | | tapetxt=root.find('tape') |
| | | version=root.find('trisurfversion') |
| | |
| | | if(self.getStatus()==0): |
| | | self.Dir=Directory(maindir=self.maindir,simdir=self.subdir) |
| | | self.Dir.makeifnotexist() |
| | | # self.Dir.goto() |
| | | cwd=Directory(maindir=os.getcwd()) |
| | | self.Dir.goto() |
| | | print("Starting trisurf-ng executable at "+self.Dir.fullpath()+"\n") |
| | | if(self.fromSnapshot==True): |
| | | params=["trisurf", "--restore-from-vtk",self.snapshotFile]+self.runArgs |
| | | else: |
| | | params=["trisurf"]+self.runArgs |
| | | subprocess.Popen (params, stdout=subprocess.DEVNULL) |
| | | cwd.goto() |
| | | else: |
| | | print("Process already running. Not starting\n") |
| | | return |
| | |
| | | statustxt="Running" |
| | | |
| | | if(self.statistics.fileOK): |
| | | report=[time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(self.statistics.startDate))),str(datetime.timedelta(microseconds=(int(self.tape.config['iterations'])-int(self.statistics.last))*self.statistics.dT)*1000), statustxt, pid, str(self.Dir.fullpath()), self.Comment.getText()] |
| | | report=[time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(self.statistics.startDate))),str(datetime.timedelta(microseconds=(int(self.tape.config['iterations'])-int(self.statistics.last))*self.statistics.dT)*1000000), statustxt, pid, str(self.Dir.fullpath()), self.Comment.getText()] |
| | | else: |
| | | report=["N/A","N/A\t",statustxt, pid, str(self.Dir.fullpath()), self.Comment.getText()] |
| | | return report |