Skip to content

Commit 8638a22

Browse files
committed
fix: use Python instead of tail
`tail` exhibits significant performance issues on files above the ~20MiB range, which is reached quite easily on the DEBUG loglevel, because of the makemkv messaging. This PR replaces the call to `tail` with a very simple native implementation, which is orders of magnitude faster.
1 parent 9850e69 commit 8638a22

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

arm/ui/json_api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import re
88
import html
9+
from collections import deque
910
from pathlib import Path
1011
import datetime
1112
import psutil
@@ -247,18 +248,18 @@ def calc_process_time(starttime, cur_iter, max_iter):
247248
return f"{str(test).split('.', maxsplit=1)[0]} - @{finish_time.strftime('%H:%M:%S')}"
248249

249250

250-
def read_log_line(log_file):
251+
def read_log_line(log_file: os.PathLike):
251252
"""
252-
Try to catch if the logfile gets delete before the job is finished\n
253-
:param log_file:
254-
:return:
253+
:param log_file: path to log file
254+
:return: the last 20 lines of the file at ``log_file``
255255
"""
256256
try:
257-
line = subprocess.check_output(['tail', '-n', '20', log_file]).splitlines()
258-
except subprocess.CalledProcessError:
257+
with open(log_file, encoding="utf8", errors="ignore") as read_log_file:
258+
lines = deque(read_log_file, maxlen=20)
259+
except OSError:
259260
app.logger.debug(f"Error while reading {log_file}, unable to calculate ETA")
260-
line = ["", ""]
261-
return line
261+
lines = ["", ""]
262+
return lines
262263

263264

264265
def read_all_log_lines(log_file):

0 commit comments

Comments
 (0)