mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-11 19:19:35 +02:00
Fix crash when the shell takes too long to start when reading the environment
According to https://docs.python.org/3/library/subprocess.html#subprocess.Popen.wait, `wait()` throws a `TimeoutExpired` exception when the process is not done after the timeout. I noticed this because kitty crashed for me. The old code looks like it's trying to wait as long as it takes for the process to finish, which is what I implemented.
This commit is contained in:
@@ -213,9 +213,16 @@ def read_shell_environment(opts=None):
|
|||||||
p = subprocess.Popen(shell + ['-l', '-c', 'env'], stdout=slave, stdin=slave, stderr=slave, start_new_session=True, close_fds=True)
|
p = subprocess.Popen(shell + ['-l', '-c', 'env'], stdout=slave, stdin=slave, stderr=slave, start_new_session=True, close_fds=True)
|
||||||
with os.fdopen(master, 'rb') as stdout, os.fdopen(slave, 'wb'):
|
with os.fdopen(master, 'rb') as stdout, os.fdopen(slave, 'wb'):
|
||||||
raw = b''
|
raw = b''
|
||||||
while p.wait(0.01) is None:
|
from subprocess import TimeoutExpired
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
ret = p.wait(0.01)
|
||||||
|
except TimeoutExpired:
|
||||||
|
ret = None
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
raw += stdout.read()
|
raw += stdout.read()
|
||||||
|
if ret is not None:
|
||||||
|
break
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user