Commit b24b1031 by ‘chizw’

[+]多进程优化

1 parent c26e9f27
import multiprocessing
import time
from funasr import AutoModel
from log.logger import log
......@@ -60,6 +61,7 @@ class model_output():
}
def handle_process(message: str):
try:
# 处理逻辑
......
......@@ -103,12 +103,13 @@ def multi_thread_consumer():
thread_kafka.main()
process_pool = multiprocessing.Pool(processes=2)
# 循环消费消息
def consume_kafka():
log.info(f"启动consume_kafka Thread name:{threading.current_thread().name}")
# 消费消息并进行逻辑处理
try:
process_pool = multiprocessing.Pool(processes=2)
for message in consumer_new:
if message is None:
continue
......@@ -117,7 +118,9 @@ def consume_kafka():
Received message value: {message.value}""")
# 处理逻辑
# funasr_service.handle_process(str(message.value.decode('utf-8')))
process_pool.apply_async(funasr_service.handle_process, (str(message.value.decode('utf-8'), )))
process_pool.apply_async(funasr_service.handle_process, str(message.value.decode('utf-8')))
process_pool.close()
process_pool.join()
print("task handle")
except Exception as e:
traceback.print_exc()
......
......@@ -236,7 +236,7 @@ def start_process():
if __name__ == "__main__":
log.info("funasr main starting...")
start_process()
start_kafka()
funasr_producer.send_wait_task()
save_path = "./audio/"
if os.path.exists(save_path):
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!