From c510584afda25ffc31cbeabd6596cfa7845b4d7a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 20 Nov 2019 11:52:25 +0530 Subject: [PATCH] Dont hang trying to read shell environment if the shell never quits. Fixes #2143 --- kitty/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitty/main.py b/kitty/main.py index f1f1c2eeb..ff8683010 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -214,7 +214,9 @@ def read_shell_environment(opts=None): with os.fdopen(master, 'rb') as stdout, os.fdopen(slave, 'wb'): raw = b'' from subprocess import TimeoutExpired - while True: + from time import monotonic + start_time = monotonic() + while monotonic() - start_time < 1.5: try: ret = p.wait(0.01) except TimeoutExpired: @@ -223,7 +225,10 @@ def read_shell_environment(opts=None): raw += stdout.read() if ret is not None: break - if p.returncode == 0: + if p.returncode is None: + log_error('Timed out waiting for shell to quit while reading shell environment') + p.kill() + elif p.returncode == 0: while True: try: x = stdout.read()