From a12e438d64571fc3e62b9ccafb13cb16673b16ec Mon Sep 17 00:00:00 2001 From: qx6ghqkz <93668667+qx6ghqkz@users.noreply.github.com> Date: Sat, 11 Jan 2025 09:30:00 +0000 Subject: [PATCH] fix: prevent logging error and subprocess not terminating Changes: - Initialise log record args to empty tuple after formatting message to prevent TypeError caused by arguments still being present in the log record when attempting to format gallery-dl log messages for the second time - Remove ANSI escape sequences before putting messages in the log queue - Use process.kill() instead of process.terminate() to ensure the download subprocess is terminated --- gallery_dl_server/__init__.py | 2 +- gallery_dl_server/output.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gallery_dl_server/__init__.py b/gallery_dl_server/__init__.py index 450f866..8544f6e 100644 --- a/gallery_dl_server/__init__.py +++ b/gallery_dl_server/__init__.py @@ -134,7 +134,7 @@ def download_task(url, options): if "Video should already be available" in record.getMessage(): log.warning("Terminating process as video is not available") - process.terminate() + process.kill() except queue.Empty: continue diff --git a/gallery_dl_server/output.py b/gallery_dl_server/output.py index 51cfee3..9be8c6d 100644 --- a/gallery_dl_server/output.py +++ b/gallery_dl_server/output.py @@ -54,11 +54,13 @@ def format(self, record): record.levelname = record.levelname.lower() message = super().format(record) - return self.remove_ansi_escape_sequences(message) + return remove_ansi_escape_sequences(message) - def remove_ansi_escape_sequences(self, text): - ansi_escape_pattern = re.compile(r"\x1B\[[0-?9;]*[mGKH]") - return ansi_escape_pattern.sub("", text) + +def remove_ansi_escape_sequences(text): + """Remove ANSI escape sequences from the given text.""" + ansi_escape_pattern = re.compile(r"\x1B\[[0-?9;]*[mGKH]") + return ansi_escape_pattern.sub("", text) def get_logger(name): @@ -122,7 +124,8 @@ def __init__(self, queue): self.queue = queue def emit(self, record): - record.msg = self.format(record) + record.msg = remove_ansi_escape_sequences(self.format(record)) + record.args = () record_dict = record_to_dict(record) self.queue.put(record_dict)