agency.resources

 1import multiprocessing
 2from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
 3
 4
 5class ResourceManager:
 6    """
 7    Singleton for globally managing concurrency primitives
 8    """
 9    _instance = None
10    _initialized = False
11
12    def __new__(cls, *args, **kwargs):
13        if cls._instance is None:
14            cls._instance = super(ResourceManager, cls).__new__(cls)
15        return cls._instance
16
17    def __init__(self, max_workers=None):
18        if not self._initialized:
19            self._max_workers = max_workers
20            self.thread_pool_executor = ThreadPoolExecutor(self._max_workers)
21            self.process_pool_executor = ProcessPoolExecutor(self._max_workers)
22            self.multiprocessing_manager = multiprocessing.Manager()
23            self._initialized = True
class ResourceManager:
 6class ResourceManager:
 7    """
 8    Singleton for globally managing concurrency primitives
 9    """
10    _instance = None
11    _initialized = False
12
13    def __new__(cls, *args, **kwargs):
14        if cls._instance is None:
15            cls._instance = super(ResourceManager, cls).__new__(cls)
16        return cls._instance
17
18    def __init__(self, max_workers=None):
19        if not self._initialized:
20            self._max_workers = max_workers
21            self.thread_pool_executor = ThreadPoolExecutor(self._max_workers)
22            self.process_pool_executor = ProcessPoolExecutor(self._max_workers)
23            self.multiprocessing_manager = multiprocessing.Manager()
24            self._initialized = True

Singleton for globally managing concurrency primitives

ResourceManager(max_workers=None)
18    def __init__(self, max_workers=None):
19        if not self._initialized:
20            self._max_workers = max_workers
21            self.thread_pool_executor = ThreadPoolExecutor(self._max_workers)
22            self.process_pool_executor = ProcessPoolExecutor(self._max_workers)
23            self.multiprocessing_manager = multiprocessing.Manager()
24            self._initialized = True