mirror of https://gitlab.com/pamhyr/pamhyr2
Solver: Fix run order.
parent
87925cb235
commit
5566d87774
|
|
@ -149,6 +149,7 @@ class AbstractSolver(object):
|
||||||
|
|
||||||
def run_input_data_fomater(self):
|
def run_input_data_fomater(self):
|
||||||
if self._cmd_input == "":
|
if self._cmd_input == "":
|
||||||
|
self._run_next()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cmd = self._cmd_input
|
cmd = self._cmd_input
|
||||||
|
|
@ -156,7 +157,7 @@ class AbstractSolver(object):
|
||||||
cmd = cmd.replace("@input", self.input_param())
|
cmd = cmd.replace("@input", self.input_param())
|
||||||
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
||||||
|
|
||||||
print(f"+ {cmd}")
|
print(f"! {cmd}")
|
||||||
|
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
exe = cmd[0]
|
exe = cmd[0]
|
||||||
|
|
@ -169,7 +170,9 @@ class AbstractSolver(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_solver(self):
|
def run_solver(self):
|
||||||
|
print("run solver")
|
||||||
if self._cmd_solver == "":
|
if self._cmd_solver == "":
|
||||||
|
self._run_next()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cmd = self._cmd_solver
|
cmd = self._cmd_solver
|
||||||
|
|
@ -177,7 +180,7 @@ class AbstractSolver(object):
|
||||||
cmd = cmd.replace("@input", self.input_param())
|
cmd = cmd.replace("@input", self.input_param())
|
||||||
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
||||||
|
|
||||||
print(f"+ {cmd}")
|
print(f"! {cmd}")
|
||||||
|
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
exe = cmd[0]
|
exe = cmd[0]
|
||||||
|
|
@ -192,13 +195,15 @@ class AbstractSolver(object):
|
||||||
|
|
||||||
def run_output_data_fomater(self):
|
def run_output_data_fomater(self):
|
||||||
if self._cmd_output == "":
|
if self._cmd_output == "":
|
||||||
|
self._run_next()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cmd = self._cmd_output
|
cmd = self._cmd_output
|
||||||
cmd = cmd.replace("@path", self._path_output)
|
cmd = cmd.replace("@path", self._path_output)
|
||||||
cmd = cmd.replace("@input", self.input_param())
|
cmd = cmd.replace("@input", self.input_param())
|
||||||
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
||||||
|
|
||||||
print(f"+ {cmd}")
|
print(f"! {cmd}")
|
||||||
|
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
exe = cmd[0]
|
exe = cmd[0]
|
||||||
|
|
@ -216,32 +221,36 @@ class AbstractSolver(object):
|
||||||
for x in s.split('\n'):
|
for x in s.split('\n'):
|
||||||
self._output.put(x)
|
self._output.put(x)
|
||||||
|
|
||||||
|
def _run_next(self):
|
||||||
|
self._step += 1
|
||||||
|
if self._step < len(self._runs):
|
||||||
|
self._runs[self._step]()
|
||||||
|
else:
|
||||||
|
self._status = STATUS.STOPED
|
||||||
|
|
||||||
def _finished(self, exit_code, exit_status):
|
def _finished(self, exit_code, exit_status):
|
||||||
if self._output is not None:
|
if self._output is not None:
|
||||||
self._output.put(exit_code)
|
self._output.put(exit_code)
|
||||||
|
|
||||||
if self._step < len(self._runs):
|
self._run_next()
|
||||||
self._runs[self._step]()
|
|
||||||
self._step += 1
|
|
||||||
else:
|
|
||||||
self._status = STATUS.STOPED
|
|
||||||
|
|
||||||
def run(self, process, output_queue):
|
def run(self, process = None, output_queue = None):
|
||||||
|
if process is not None:
|
||||||
self._process = process
|
self._process = process
|
||||||
|
if output_queue is not None:
|
||||||
self._output = output_queue
|
self._output = output_queue
|
||||||
|
|
||||||
self._process.readyRead.connect(self._data_ready)
|
self._process.readyRead.connect(self._data_ready)
|
||||||
self._process.finished.connect(self._finished)
|
self._process.finished.connect(self._finished)
|
||||||
|
|
||||||
self._step = 0
|
|
||||||
self._runs = [
|
self._runs = [
|
||||||
self.run_input_data_fomater,
|
self.run_input_data_fomater,
|
||||||
self.run_solver,
|
self.run_solver,
|
||||||
self.run_output_data_fomater,
|
self.run_output_data_fomater,
|
||||||
]
|
]
|
||||||
|
self._step = 0
|
||||||
self._runs[self._step]()
|
# Run first step
|
||||||
self._step += 1
|
self._runs[0]()
|
||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
if self._process is None:
|
if self._process is None:
|
||||||
|
|
@ -252,16 +261,13 @@ class AbstractSolver(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def start(self, process = None):
|
def start(self, process = None):
|
||||||
if process is not None:
|
|
||||||
self._process = process
|
|
||||||
|
|
||||||
if _signal:
|
if _signal:
|
||||||
if self._status == STATUS.PAUSED:
|
if self._status == STATUS.PAUSED:
|
||||||
os.kill(self._process.pid(), SIGCONT)
|
os.kill(self._process.pid(), SIGCONT)
|
||||||
self._status = STATUS.RUNNING
|
self._status = STATUS.RUNNING
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.run_solver()
|
self.run(process)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,10 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
self._log(f" *** Run solver {self._solver.name}", color="blue")
|
self._log(f" *** Run solver {self._solver.name}", color="blue")
|
||||||
self._solver.run(self._process, self._output)
|
self._solver.run(
|
||||||
|
process = self._process,
|
||||||
|
output_queue = self._output
|
||||||
|
)
|
||||||
|
|
||||||
def new_process(self, parent):
|
def new_process(self, parent):
|
||||||
new = QProcess(parent)
|
new = QProcess(parent)
|
||||||
|
|
@ -180,9 +183,14 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self._log(s)
|
self._log(s)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self._log(" *** Start", color="blue")
|
|
||||||
if self._solver.is_stoped():
|
if self._solver.is_stoped():
|
||||||
|
self._log(f" *** Export study {self._solver.name}", color="blue")
|
||||||
|
self._solver.export(self._study, self._workdir, qlog = self._output)
|
||||||
|
self.update()
|
||||||
|
|
||||||
self._process = self.new_process(self._parent)
|
self._process = self.new_process(self._parent)
|
||||||
|
|
||||||
|
self._log(" *** Start", color="blue")
|
||||||
self._solver.start(self._process)
|
self._solver.start(self._process)
|
||||||
|
|
||||||
self.find(QAction, "action_start").setEnabled(False)
|
self.find(QAction, "action_start").setEnabled(False)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue