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) entry = json.loads(line)
yield entry yield entry
def has_previous_error() -> Exception: def has_previous_error() -> str:
for entry in read_db(): for entry in read_db():
return entry.get('error') return entry.get('error')
else: else:

View file

@ -5,6 +5,7 @@ from typing import List, BinaryIO, Iterator
from io import DEFAULT_BUFFER_SIZE from io import DEFAULT_BUFFER_SIZE
from time import mktime from time import mktime
from datetime import datetime from datetime import datetime
from signal import SIGINT, SIGTERM, Signals
logger = logging.getLogger() logger = logging.getLogger()
class UnknownQuestionError(subprocess.SubprocessError): 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 captures stdout and stderr and
automatically handles [y/n] questions of pacman automatically handles [y/n] questions of pacman
''' '''
def terminate(p: subprocess.Popen, timeout: int = 30) -> None: def terminate(p: subprocess.Popen, timeout: int = 30, signal: Signals = SIGTERM) -> None:
p.terminate() p.send_signal(signal)
try: try:
p.wait(timeout=30) p.wait(timeout=30)
except subprocess.TimeoutExpired: 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.write('y\n')
p.stdin.flush() p.stdin.flush()
elif line.lower().endswith('[y/n]'): elif line.lower().endswith('[y/n]'):
terminate(p) terminate(p, signal=SIGINT)
raise UnknownQuestionError(line, output) raise UnknownQuestionError(line, output)
if (ret := p.wait()) != 0: if (ret := p.wait()) != 0: