Better fix for long running highlight workers

This commit is contained in:
Kovid Goyal 2018-08-04 17:41:37 +05:30
parent 9a1f14d05c
commit 42cabace47
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 2 deletions

View File

@ -122,8 +122,6 @@ def highlight_line(line):
def highlight_for_diff(path, aliases):
ans = []
lines = lines_for_path(path)
if len(lines) > 10000:
return ans
hd = highlight_data('\n'.join(lines), path, aliases)
if hd is not None:
for line in hd.splitlines():
@ -135,6 +133,7 @@ def highlight_collection(collection, aliases=None):
jobs = {}
ans = {}
with concurrent.futures.ProcessPoolExecutor(max_workers=os.cpu_count()) as executor:
highlight_collection.processes = executor._processes
for path, item_type, other_path in collection:
if item_type != 'rename':
for p in (path, other_path):

View File

@ -3,6 +3,7 @@
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
import signal
import sys
import warnings
from collections import defaultdict
@ -508,6 +509,13 @@ def showwarning(message, category, filename, lineno, file=None, line=None):
usage = 'file_or_directory_left file_or_directory_right'
def terminate_processes(processes):
for pid in processes:
os.kill(pid, signal.SIGTERM)
for pid in processes:
os.kill(pid, signal.SIGKILL)
def main(args):
warnings.showwarning = showwarning
args, items = parse_args(args[1:], OPTIONS, usage, help_text, 'kitty +kitten diff')
@ -530,6 +538,8 @@ def main(args):
for message in showwarning.warnings:
from kitty.utils import safe_print
safe_print(message, file=sys.stderr)
processes = getattr(highlight_collection, 'processes', ())
terminate_processes(tuple(processes))
if loop.return_code != 0:
if handler.report_traceback_on_exit:
print(handler.report_traceback_on_exit, file=sys.stderr)