Skip to content
Snippets Groups Projects
Commit 098ccd55 authored by mads's avatar mads
Browse files

Merge branch 'clustertools' of...

Merge branch 'clustertools' of https://gitlab.windenergy.dtu.dk/toolbox/WindEnergyToolbox into clustertools

# Conflicts:
#	wetb/hawc2/cluster_simulation.py
parents a695313a afe9ba18
No related branches found
No related tags found
2 merge requests!6Clustertools,!5Clustertools
Pipeline #
...@@ -11,9 +11,8 @@ from wetb.hawc2.htc_file import HTCFile ...@@ -11,9 +11,8 @@ from wetb.hawc2.htc_file import HTCFile
from wetb.hawc2.log_file import LogFile from wetb.hawc2.log_file import LogFile
from threading import Timer, Thread from threading import Timer, Thread
import sys import sys
from multiprocessing.process import Process from multiprocessing import Process
import psutil import psutil
from wetb.utils.process_exec import process, exec_process
import subprocess import subprocess
import shutil import shutil
import json import json
...@@ -63,7 +62,6 @@ class Simulation(object): ...@@ -63,7 +62,6 @@ class Simulation(object):
self.last_status = self._status self.last_status = self._status
self.errors = [] self.errors = []
self.thread = Thread(target=self.simulate_distributed) self.thread = Thread(target=self.simulate_distributed)
self.dist_thread = Thread()
self.hawc2exe = hawc2exe self.hawc2exe = hawc2exe
self.simulationThread = SimulationThread(self) self.simulationThread = SimulationThread(self)
self.timer = RepeatedTimer(self.update_status) self.timer = RepeatedTimer(self.update_status)
...@@ -82,9 +80,8 @@ class Simulation(object): ...@@ -82,9 +80,8 @@ class Simulation(object):
self.show_status() self.show_status()
def update_status(self, *args, **kwargs): def update_status(self, *args, **kwargs):
self.logFile.update_status()
if self.status in [INITIALIZING, SIMULATING]: if self.status in [INITIALIZING, SIMULATING]:
self.logFile.update_status()
if self.logFile.status == log_file.SIMULATING: if self.logFile.status == log_file.SIMULATING:
self._status = SIMULATING self._status = SIMULATING
if self.logFile.status == log_file.DONE and self.is_simulating is False: if self.logFile.status == log_file.DONE and self.is_simulating is False:
...@@ -111,7 +108,6 @@ class Simulation(object): ...@@ -111,7 +108,6 @@ class Simulation(object):
self.last_status = self.logFile.status self.last_status = self.logFile.status
def additional_files(self): def additional_files(self):
additional_files_file = os.path.join(self.modelpath, 'additional_files.txt') additional_files_file = os.path.join(self.modelpath, 'additional_files.txt')
additional_files = {} additional_files = {}
...@@ -247,11 +243,16 @@ class Simulation(object): ...@@ -247,11 +243,16 @@ class Simulation(object):
def show_message(self, msg, title="Information"): def show_message(self, msg, title="Information"):
print (msg) print (msg)
def start(self): def start(self, update_interval=1):
"""Start non blocking distributed simulation""" """Start non blocking distributed simulation"""
self.timer.start(1000) self.timer.start(update_interval*1000)
self.thread.start() self.thread.start()
def wait(self):
self.thread.join()
self.timer.stop()
self.update_status()
def stop(self): def stop(self):
self.timer.stop() self.timer.stop()
self.simulationThread.process.kill() self.simulationThread.process.kill()
...@@ -263,22 +264,6 @@ class Simulation(object): ...@@ -263,22 +264,6 @@ class Simulation(object):
self.status = ABORTED self.status = ABORTED
self.update_status() self.update_status()
#class SimulationProcess(Process):
#
# def __init__(self, modelpath, htcfile, hawc2exe="HAWC2MB.exe"):
# Process.__init__(self)
# self.modelpath = modelpath
# self.htcfile = os.path.abspath(htcfile)
# self.hawc2exe = hawc2exe
# self.res = [0, "", "", ""]
# self.process = process([self.hawc2exe, self.htcfile] , self.modelpath)
#
#
# def run(self):
# p = psutil.Process(os.getpid())
# p.nice = psutil.BELOW_NORMAL_PRIORITY_CLASS
# exec_process(self.process)
class SimulationThread(Thread): class SimulationThread(Thread):
...@@ -291,15 +276,15 @@ class SimulationThread(Thread): ...@@ -291,15 +276,15 @@ class SimulationThread(Thread):
def start(self): def start(self):
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
CREATE_NO_WINDOW = 0x08000000 CREATE_NO_WINDOW = 0x08000000
modelpath = self.modelpath modelpath = self.modelpath
htcfile = os.path.relpath(self.sim.htcFile.filename, self.sim.modelpath) htcfile = os.path.relpath(self.sim.htcFile.filename, self.sim.modelpath)
hawc2exe = self.sim.hawc2exe hawc2exe = self.sim.hawc2exe
stdout = self.sim.stdout_filename stdout = self.sim.stdout_filename
self.process = subprocess.Popen('"%s" %s 1> %s 2>&1' % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW) if os.name=="nt":
self.process = subprocess.Popen('"%s" %s 1> %s 2>&1' % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW)
else:
self.process = subprocess.Popen('wine "%s" %s 1> %s 2>&1' % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath)
Thread.start(self) Thread.start(self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment