mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
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:
@@ -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"
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user