feat 多线程处理事件

This commit is contained in:
jxxghp
2023-10-17 19:04:42 +08:00
parent e57b6adba1
commit 453ef94e4d
3 changed files with 47 additions and 3 deletions

31
app/helper/thread.py Normal file
View File

@ -0,0 +1,31 @@
from concurrent.futures import ThreadPoolExecutor
from app.utils.singleton import Singleton
class ThreadHelper(metaclass=Singleton):
"""
线程池管理
"""
def __init__(self, max_workers=50):
self.pool = ThreadPoolExecutor(max_workers=max_workers)
def submit(self, func, *args, **kwargs):
"""
提交任务
:param func: 函数
:param args: 参数
:param kwargs: 参数
:return: future
"""
return self.pool.submit(func, *args, **kwargs)
def shutdown(self):
"""
关闭线程池
:return:
"""
self.pool.shutdown()
def __del__(self):
self.shutdown()