From 4715b7e47051652ec3f4738b1aeaf06a3a4f6ae7 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 26 Jun 2023 15:37:45 +0200 Subject: [PATCH] Solver: Fix for windows version. --- src/Solver/ASolver.py | 28 +++++++++++++++++++--------- src/View/RunSolver/Window.py | 17 +++++++++++++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/Solver/ASolver.py b/src/Solver/ASolver.py index 6e2527c9..371edcad 100644 --- a/src/Solver/ASolver.py +++ b/src/Solver/ASolver.py @@ -2,7 +2,12 @@ import os -from signal import SIGTERM, SIGSTOP, SIGCONT +try: + from signal import SIGTERM, SIGSTOP, SIGCONT + _signal = True +except: + _signal = False + from enum import Enum from Model.Except import NotImplementedMethodeError @@ -206,21 +211,26 @@ class AbstractSolver(object): if process is not None: self._process = process - if self._status == STATUS.PAUSED: - os.kill(self._process.pid(), SIGCONT) - self._status = STATUS.RUNNING + if _signal: + if self._status == STATUS.PAUSED: + os.kill(self._process.pid(), SIGCONT) + self._status = STATUS.RUNNING + else: + self.run_solver() else: self.run_solver() return True def pause(self): - if self._process is None: - return False + if _signal: + if self._process is None: + return False - os.kill(self._process.pid(), SIGSTOP) - self._status = STATUS.PAUSED - return True + os.kill(self._process.pid(), SIGSTOP) + self._status = STATUS.PAUSED + return True + return False def stop(self): if self._process is None: diff --git a/src/View/RunSolver/Window.py b/src/View/RunSolver/Window.py index 2efe081a..9ac84a82 100644 --- a/src/View/RunSolver/Window.py +++ b/src/View/RunSolver/Window.py @@ -29,6 +29,12 @@ from PyQt5.QtWidgets import ( from View.RunSolver.Log.Window import SolverLogFileWindow +try: + from signal import SIGTERM, SIGSTOP, SIGCONT + _signal = True +except: + _signal = False + _translate = QCoreApplication.translate class SelectSolverWindow(ASubWindow, ListedSubWindow): @@ -126,7 +132,11 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): def setup_action(self): self.find(QAction, "action_start").setEnabled(False) - self.find(QAction, "action_pause").setEnabled(True) + if _signal: + self.find(QAction, "action_pause").setEnabled(True) + else: + self.find(QAction, "action_pause").setEnabled(False) + self.find(QAction, "action_stop").setEnabled(True) self.find(QAction, "action_log_file").setEnabled(False) @@ -176,7 +186,10 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self._solver.start(self._process) self.find(QAction, "action_start").setEnabled(False) - self.find(QAction, "action_pause").setEnabled(True) + if _signal: + self.find(QAction, "action_pause").setEnabled(True) + else: + self.find(QAction, "action_pause").setEnabled(False) self.find(QAction, "action_stop").setEnabled(True) self.find(QAction, "action_log_file").setEnabled(False) -- GitLab