Skip to content

Commit

Permalink
fix: prevent logging error and subprocess not terminating
Browse files Browse the repository at this point in the history
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
  • Loading branch information
qx6ghqkz committed Jan 11, 2025
1 parent d351dfe commit a12e438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gallery_dl_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions gallery_dl_server/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a12e438

Please sign in to comment.