From c72f85f0171bd6177e709636bd120881ed374366 Mon Sep 17 00:00:00 2001 From: zhanghan2021 Date: Tue, 28 Nov 2023 10:08:08 +0800 Subject: [PATCH] Put the decorated function into the thread pool --- common/threadpool.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/threadpool.py b/common/threadpool.py index 8a613a9..c199fd8 100644 --- a/common/threadpool.py +++ b/common/threadpool.py @@ -2,6 +2,7 @@ #!/usr/bin/env python # cython:language_level=3 +import functools from concurrent.futures import ThreadPoolExecutor from common.decorator_wrap import DecoratorWrap @@ -13,4 +14,14 @@ class ThreadPool(): self.__thread_obj = ThreadPoolExecutor(self.__max_threads) # Store the created thread self.__generate_list = [] - \ No newline at end of file + + def threaded_pool(self, func): + ''' + Externally callable thread pool decorator + ''' + @functools.wraps(func) + def inner(*args, **kwargs): + obj = self.__thread_obj.submit(func, *args) + self.__generate_list.append(obj) + return inner + \ No newline at end of file -- Gitee