Also prevent long running diff workers from causing a hang on exit
This commit is contained in:
parent
927bfcd37a
commit
e05d48a574
@ -25,7 +25,7 @@ from .collect import (
|
|||||||
set_highlight_data
|
set_highlight_data
|
||||||
)
|
)
|
||||||
from .config import init_config
|
from .config import init_config
|
||||||
from .patch import Differ, set_diff_command
|
from .patch import Differ, set_diff_command, worker_processes
|
||||||
from .render import ImageSupportWarning, LineRef, render_diff
|
from .render import ImageSupportWarning, LineRef, render_diff
|
||||||
from .search import BadRegex, Search
|
from .search import BadRegex, Search
|
||||||
|
|
||||||
@ -511,9 +511,10 @@ usage = 'file_or_directory_left file_or_directory_right'
|
|||||||
|
|
||||||
def terminate_processes(processes):
|
def terminate_processes(processes):
|
||||||
for pid in processes:
|
for pid in processes:
|
||||||
os.kill(pid, signal.SIGTERM)
|
try:
|
||||||
for pid in processes:
|
os.kill(pid, signal.SIGKILL)
|
||||||
os.kill(pid, signal.SIGKILL)
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
@ -538,8 +539,9 @@ def main(args):
|
|||||||
for message in showwarning.warnings:
|
for message in showwarning.warnings:
|
||||||
from kitty.utils import safe_print
|
from kitty.utils import safe_print
|
||||||
safe_print(message, file=sys.stderr)
|
safe_print(message, file=sys.stderr)
|
||||||
processes = getattr(highlight_collection, 'processes', ())
|
highlight_processes = getattr(highlight_collection, 'processes', ())
|
||||||
terminate_processes(tuple(processes))
|
terminate_processes(tuple(highlight_processes))
|
||||||
|
terminate_processes(tuple(worker_processes))
|
||||||
if loop.return_code != 0:
|
if loop.return_code != 0:
|
||||||
if handler.report_traceback_on_exit:
|
if handler.report_traceback_on_exit:
|
||||||
print(handler.report_traceback_on_exit, file=sys.stderr)
|
print(handler.report_traceback_on_exit, file=sys.stderr)
|
||||||
|
|||||||
@ -14,6 +14,7 @@ from .diff_speedup import changed_center
|
|||||||
left_lines = right_lines = None
|
left_lines = right_lines = None
|
||||||
GIT_DIFF = 'git diff --no-color --no-ext-diff --exit-code -U_CONTEXT_ --no-index --'
|
GIT_DIFF = 'git diff --no-color --no-ext-diff --exit-code -U_CONTEXT_ --no-index --'
|
||||||
DIFF_DIFF = 'diff -p -U _CONTEXT_ --'
|
DIFF_DIFF = 'diff -p -U _CONTEXT_ --'
|
||||||
|
worker_processes = []
|
||||||
|
|
||||||
|
|
||||||
def find_differ():
|
def find_differ():
|
||||||
@ -43,8 +44,10 @@ def run_diff(file1, file2, context=3):
|
|||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
cmd + [path1, path2],
|
cmd + [path1, path2],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
|
||||||
|
worker_processes.append(p.pid)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
returncode = p.wait()
|
returncode = p.wait()
|
||||||
|
worker_processes.remove(p.pid)
|
||||||
if returncode in (0, 1):
|
if returncode in (0, 1):
|
||||||
return True, returncode == 1, stdout.decode('utf-8')
|
return True, returncode == 1, stdout.decode('utf-8')
|
||||||
return False, returncode, stderr.decode('utf-8')
|
return False, returncode, stderr.decode('utf-8')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user