diff --git a/src/pacroller/main.py b/src/pacroller/main.py index 9c15b48..f7f0a7d 100644 --- a/src/pacroller/main.py +++ b/src/pacroller/main.py @@ -165,7 +165,7 @@ def read_db() -> Iterator[dict]: entry = json.loads(line) yield entry -def has_previous_error() -> Exception: +def has_previous_error() -> str: for entry in read_db(): return entry.get('error') else: diff --git a/src/pacroller/utils.py b/src/pacroller/utils.py index bc0b8d2..45d0ad4 100644 --- a/src/pacroller/utils.py +++ b/src/pacroller/utils.py @@ -5,6 +5,7 @@ from typing import List, BinaryIO, Iterator from io import DEFAULT_BUFFER_SIZE from time import mktime from datetime import datetime +from signal import SIGINT, SIGTERM, Signals logger = logging.getLogger() class UnknownQuestionError(subprocess.SubprocessError): @@ -19,8 +20,8 @@ def execute_with_io(command: List[str], timeout: int = 3600) -> List[str]: captures stdout and stderr and automatically handles [y/n] questions of pacman ''' - def terminate(p: subprocess.Popen, timeout: int = 30) -> None: - p.terminate() + def terminate(p: subprocess.Popen, timeout: int = 30, signal: Signals = SIGTERM) -> None: + p.send_signal(signal) try: p.wait(timeout=30) except subprocess.TimeoutExpired: @@ -55,7 +56,7 @@ def execute_with_io(command: List[str], timeout: int = 3600) -> List[str]: p.stdin.write('y\n') p.stdin.flush() elif line.lower().endswith('[y/n]'): - terminate(p) + terminate(p, signal=SIGINT) raise UnknownQuestionError(line, output) if (ret := p.wait()) != 0: