Files
wehub-resource-sync 39a086b41b
Build Windows CPU / build (push) Has been cancelled
Build Windows CUDA 10.2 / build (push) Has been cancelled
Build Windows CUDA 11.8 / build (push) Has been cancelled
Build Windows CUDA 12.6 / build (push) Has been cancelled
Build Windows DirectML / build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:08 +08:00

67 lines
2.0 KiB
Python

import multiprocessing
import threading
from enum import Enum
class Command(Enum):
FINISH = 0,
PROGRESS = 1,
LOG = 2,
MANAGE_PROCESS = 3,
ERROR = 4,
class SubtitleExtractorRemoteCall:
"""
远程回调函数类,用于在多进程环境中传递回调函数
"""
def __init__(self):
self.queue = multiprocessing.Queue()
self.callbacks = {}
self.running = True
threading.Thread(target=self.run, daemon=True).start()
def run(self):
try:
while self.running:
cmd, args = self.queue.get(block=True)
if cmd == Command.FINISH:
break
callback = self.callbacks.get(cmd)
if callback:
callback(*args)
finally:
self.running = False
def stop(self):
self.running = False
def register_update_progress_callback(self, callback):
self.callbacks[Command.PROGRESS] = callback
def register_log_callback(self, callback):
self.callbacks[Command.LOG] = callback
def register_manage_process_callback(self, callback):
self.callbacks[Command.MANAGE_PROCESS] = callback
def register_error_callback(self, callback):
self.callbacks[Command.ERROR] = callback
@staticmethod
def remote_call_update_progress(queue, progress_ocr, progress_frame_extract, progress_total, isFinished, progress_post=0):
queue.put((Command.PROGRESS, (progress_ocr, progress_frame_extract, progress_total, isFinished, progress_post,)))
@staticmethod
def remote_call_append_log(queue, *args):
queue.put((Command.LOG, (*args,)))
@staticmethod
def remote_call_finish(queue, *args):
queue.put((Command.FINISH, (None,)))
@staticmethod
def remote_call_catch_error(queue, e):
queue.put((Command.ERROR, (e,)))
@staticmethod
def remote_call_manage_process(queue, pid):
queue.put((Command.MANAGE_PROCESS, (pid,)))