Solver: Minor change.

mesh
Pierre-Antoine Rouby 2023-06-20 09:40:55 +02:00
parent 21c59dbcac
commit d893db4ef7
2 changed files with 26 additions and 13 deletions

View File

@ -3,7 +3,6 @@
import os import os
from signal import SIGTERM, SIGSTOP, SIGCONT from signal import SIGTERM, SIGSTOP, SIGCONT
from subprocess import Popen, PIPE, STDOUT, TimeoutExpired
from enum import Enum from enum import Enum
from Model.Except import NotImplementedMethodeError from Model.Except import NotImplementedMethodeError
@ -12,9 +11,6 @@ class STATUS(Enum):
NOT_LAUNCHED = -1 NOT_LAUNCHED = -1
STOPED = 0 STOPED = 0
RUNNING = 1 RUNNING = 1
FAILED = 2
CONF_ERROR = 3
KILLED = 4
PAUSED = 5 PAUSED = 5
class AbstractSolver(object): class AbstractSolver(object):
@ -90,6 +86,15 @@ class AbstractSolver(object):
def status(self, status): def status(self, status):
self._status = status self._status = status
def is_running(self):
return self._status == STATUS.RUNNING
def is_paused(self):
return self._status == STATUS.PAUSED
def is_stoped(self):
return self._status == STATUS.STOPED
@name.setter @name.setter
def name(self, name): def name(self, name):
self._name = name self._name = name
@ -137,6 +142,7 @@ class AbstractSolver(object):
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._status = STATUS.RUNNING
return True return True
def run_output_data_fomater(self): def run_output_data_fomater(self):
@ -153,6 +159,7 @@ class AbstractSolver(object):
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)
self._status = STATUS.STOPED
def run(self, process, output_queue): def run(self, process, output_queue):
self._process = process self._process = process
@ -167,12 +174,12 @@ class AbstractSolver(object):
return True return True
self._process.kill() self._process.kill()
self._status = STATUS.KILLED self._status = STATUS.STOPED
return True return True
def start(self): def start(self, process = None):
if self._process is None: if process is not None:
return False self._process = process
if self._status == STATUS.PAUSED: if self._status == STATUS.PAUSED:
os.kill(self._process.pid(), SIGCONT) os.kill(self._process.pid(), SIGCONT)

View File

@ -74,6 +74,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
study=None, config=None, study=None, config=None,
solver=None, parent=None): solver=None, parent=None):
self._title = title self._title = title
self._parent = parent
self._study = study self._study = study
self._config = config self._config = config
@ -123,18 +124,25 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
color = "blue" if msg == 0 else "red" color = "blue" if msg == 0 else "red"
self.find(QTextEdit, "textEdit")\ self.find(QTextEdit, "textEdit")\
.append(f"<font color=\"{color}\">" + .append(f"<font color=\"{color}\">" +
f"*** Solver finished with code {msg}" + f" *** Finished with code {msg}" +
"</font>") "</font>")
def update(self): def update(self):
if self._solver.is_stoped():
self.find(QAction, "action_start").setEnabled(True)
self.find(QAction, "action_pause").setEnabled(False)
self.find(QAction, "action_stop").setEnabled(False)
while self._output.qsize() != 0: while self._output.qsize() != 0:
s = self._output.get() s = self._output.get()
self._log(s) self._log(s)
def start(self): def start(self):
self._log(" *** Start", color="blue") self._log(" *** Start", color="blue")
if self._solver.is_stoped():
self._solver.start() self._process = QProcess(self._parent)
self._solver.start(self._process)
self.find(QAction, "action_start").setEnabled(False) self.find(QAction, "action_start").setEnabled(False)
self.find(QAction, "action_pause").setEnabled(True) self.find(QAction, "action_pause").setEnabled(True)
@ -142,7 +150,6 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
def pause(self): def pause(self):
self._log(" *** Pause", color="blue") self._log(" *** Pause", color="blue")
self._solver.pause() self._solver.pause()
self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_start").setEnabled(True)
@ -151,7 +158,6 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
def stop(self): def stop(self):
self._log(" *** Stop", color="blue") self._log(" *** Stop", color="blue")
self._solver.kill() self._solver.kill()
self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_start").setEnabled(True)