diff --git a/abogen/web/conversion_runner.py b/abogen/web/conversion_runner.py index a5c0b0a..84e067c 100644 --- a/abogen/web/conversion_runner.py +++ b/abogen/web/conversion_runner.py @@ -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" diff --git a/docker-compose.yaml b/docker-compose.yaml index 057352f..ff39617 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,6 +33,9 @@ services: # below if you are deploying to a CPU-only host. deploy: resources: + limits: + cpus: '4.0' + memory: 8G reservations: devices: - capabilities: [gpu]