Dont hang trying to read shell environment if the shell never quits. Fixes #2143

This commit is contained in:
Kovid Goyal 2019-11-20 11:52:25 +05:30
parent 738878c2ff
commit c510584afd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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()