# -*- encoding: utf-8 -*- """ @File : GlobalThreadPoolObject.py @Time : 2024/8/20 19:49 @Author : stephen @Email : zhangdongming@asj6.wecom.work @Software: PyCharm """ import threading from concurrent.futures import ThreadPoolExecutor from AnsjerPush.config import CONFIG_EUR, CONFIG_INFO, CONFIG_CN, CONFIG_US class GlobalThreadPool: _instance = None _lock = threading.Lock() def __new__(cls): if not cls._instance: with cls._lock: if not cls._instance: cls._instance = super(GlobalThreadPool, cls).__new__(cls) max_workers = 20 if CONFIG_INFO == CONFIG_US or CONFIG_INFO == CONFIG_EUR: max_workers = 300 elif CONFIG_INFO == CONFIG_CN: max_workers = 100 cls._instance.executor = ThreadPoolExecutor( thread_name_prefix="global-thread-pool" ) return cls._instance def submit(self, fn, *args, **kwargs): return self.executor.submit(fn, *args, **kwargs) def shutdown(self, wait=True): self.executor.shutdown(wait)