fix several bugs

This commit is contained in:
JerryXiao 2021-03-20 12:13:51 +08:00
parent 8de777b4cc
commit fbcaae3db9
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 5 additions and 4 deletions

View file

@ -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:

View file

@ -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: