diff options
author | V3n3RiX <venerix@koprulu.sector> | 2023-04-08 21:54:58 +0100 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2023-04-08 21:54:58 +0100 |
commit | f47c51c17f4d743ecd15f977097c5ae6fb82a82e (patch) | |
tree | a5cc1c698e09cbc3997134cd5d8b9a1ba6484843 | |
parent | badc3710e1afb5ac7339b9c17d72a3078f91d881 (diff) |
getenv : make sure it stops with keyboard interrupt
-rw-r--r-- | src/backend/getenv.py | 18 |
1 files changed, 17 insertions, 1 deletions
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 |