From f47c51c17f4d743ecd15f977097c5ae6fb82a82e Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 8 Apr 2023 21:54:58 +0100 Subject: getenv : make sure it stops with keyboard interrupt --- src/backend/getenv.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/backend/getenv.py') diff --git a/src/backend/getenv.py b/src/backend/getenv.py index 3399288..108a90c 100644 --- a/src/backend/getenv.py +++ b/src/backend/getenv.py @@ -2,10 +2,18 @@ import io import os +import signal import subprocess import sisyphus.getfs +def sigint_handler(signal, frame): + sys.exit(0) + + +signal.signal(signal.SIGINT, sigint_handler) + + def bhst_addr(): bhst_addr = [] p_exe = subprocess.Popen( @@ -14,7 +22,15 @@ def bhst_addr(): for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"): if "PORTAGE_BINHOST" in p_out: bhst_addr = p_out.rstrip().split("=")[1].strip('\"') - p_exe.wait() + try: + p_exe.wait() + except KeyboardInterrupt: + p_exe.terminate() + try: + p_exe.wait(1) + except subprocess.TimeoutExpired: + p_exe.kill() + sys.exit() return bhst_addr -- cgit v1.2.3