Solver: Fix running pipeline.

setup.py
Pierre-Antoine Rouby 2023-12-13 15:57:47 +01:00
parent c3cae35de4
commit 7aee4c64a3
3 changed files with 30 additions and 14 deletions

View File

@ -172,12 +172,13 @@ class CommandLineSolver(AbstractSolver):
if not os.path.exists(exe): if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists" error = f"[ERROR] Path {exe} do not exists"
logger.info(error) logger.warning(error)
return error return error
self._process.start( self._process.start(
exe, args, exe, args,
) )
self._process.waitForStarted()
return True return True
@ -191,7 +192,7 @@ class CommandLineSolver(AbstractSolver):
if not os.path.exists(exe): if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists" error = f"[ERROR] Path {exe} do not exists"
logger.info(error) logger.warning(error)
return error return error
self._process.start( self._process.start(
@ -212,37 +213,48 @@ class CommandLineSolver(AbstractSolver):
if not os.path.exists(exe): if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists" error = f"[ERROR] Path {exe} do not exists"
logger.info(error) logger.warning(error)
return error return error
self._process.start( self._process.start(
exe, args, exe, args,
) )
self._process.waitForStarted()
return True return True
def _data_ready(self): def _data_ready(self):
# Read process output and put lines in queue # Read process output and put lines in queue
s = self._process.readAll().data().decode() s = self._process.readAll().data().decode()
if self._output is not None: if self._output is not None:
for x in s.split('\n'): for x in s.split('\n'):
self._output.put(x) self._output.put(x)
def _run_next(self, study):
self._step += 1
if self._step < len(self._runs):
res = self._runs[self._step](study)
if res is not True:
self._output.put(res)
else:
self._status = STATUS.STOPED
def _finished(self, study, exit_code, exit_status): def _finished(self, study, 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)
logger.debug(
"Process finished with " +
f"code: {exit_code}, status: {exit_status}"
)
self._run_next(study) self._run_next(study)
def _run_next(self, study):
self._step += 1
if self._step >= len(self._runs):
self._status = STATUS.STOPED
return
fn = self._runs[self._step]
res = fn(study)
if res is not True:
self._output.put(res)
def run(self, study, process=None, output_queue=None): def run(self, study, process=None, output_queue=None):
self._study = study self._study = study
@ -255,7 +267,8 @@ class CommandLineSolver(AbstractSolver):
# Connect / reconnect signal # Connect / reconnect signal
self._process.readyRead.connect(self._data_ready) self._process.readyRead.connect(self._data_ready)
self._process.finished.connect( self._process.finished.connect(
lambda c, s: self._finished(study, c, s)) lambda c, s: self._finished(study, c, s)
)
# Prepare running step # Prepare running step
self._runs = [ self._runs = [
@ -265,6 +278,8 @@ class CommandLineSolver(AbstractSolver):
] ]
self._step = 0 self._step = 0
self._status = STATUS.RUNNING
# Run first step # Run first step
res = self._runs[0](study) res = self._runs[0](study)
if res is not True: if res is not True:

View File

@ -20,7 +20,7 @@ import os
import logging import logging
import numpy as np import numpy as np
from tools import timer from tools import timer, trace
from Solver.CommandLine import CommandLineSolver from Solver.CommandLine import CommandLineSolver
from Checker.Mage import MageNetworkGraphChecker from Checker.Mage import MageNetworkGraphChecker

View File

@ -273,6 +273,7 @@ class SolverLogWindow(PamhyrWindow):
def _update_logs_all(self): def _update_logs_all(self):
while self._output.qsize() != 0: while self._output.qsize() != 0:
s = self._output.get() s = self._output.get()
if type(s) is str and "[ERROR]" in s: if type(s) is str and "[ERROR]" in s:
self._log(s, color="red") self._log(s, color="red")
else: else: