McCloudS / subgen

Autogenerate subtitles using OpenAI Whisper Model via Jellyfin, Plex, Emby, Tautulli, or Bazarr
MIT License
453 stars 45 forks source link

Add queue lock to force running only one job at a time #51

Closed xhzhu0628 closed 4 months ago

xhzhu0628 commented 5 months ago

import threading from queue import Queue

start queue

task_queue = Queue()

start queue lock

task_queue_lock = threading.Lock()

def transcription_worker(): while True: task = task_queue.get()

    gen_subtitles(task['path'], task['transcribe_or_translate'], task['force'])

    task_queue.task_done()
    time.sleep(5*60)
    # show queue
    with task_queue_lock:
        print(f"There are {task_queue.qsize()} tasks left in the queue.")

activate thread

threading.Thread(target=transcription_worker, daemon=True).start()

McCloudS commented 4 months ago

Queuing appears to mostly work for me, but I'm open to any PRs. Whisper has a threads/workers option. Converting to discussion if you wanted to try a PR.

cpu_threads=whisper_threads, num_workers=concurrent_transcriptions