fix: Implement garbage collection in run_conversion_job to prevent memory accumulation and add resource limits in docker-compose for better performance

This commit is contained in:
JB
2025-11-30 05:37:40 -08:00
parent 540b191d5b
commit 040bce1bc1
2 changed files with 15 additions and 0 deletions
+12
View File
@@ -8,6 +8,7 @@ import subprocess
import sys
import tempfile
import traceback
import gc
from datetime import datetime
from collections import defaultdict
from contextlib import ExitStack
@@ -1949,6 +1950,17 @@ def run_conversion_job(job: Job) -> None:
if subtitle_writer:
subtitle_writer.close()
# Explicitly release the pipeline and force garbage collection to prevent
# memory accumulation in the worker process, which can lead to host lockups.
pipeline = None
gc.collect()
try:
import torch
if torch.cuda.is_available():
torch.cuda.empty_cache()
except ImportError:
pass
if (
audio_output_path
and job.output_format.lower() == "m4b"