Skip to content

Commit

Permalink
Parameterization of Max Workers in ResourceManager (#185)
Browse files Browse the repository at this point in the history
Co-authored-by: Miguel Díaz <[email protected]>
  • Loading branch information
migueldl96 and Miguel Díaz authored Apr 23, 2024
1 parent 5510409 commit e7ff41b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions agency/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class ResourceManager:
_instance = None
_initialized = False

def __new__(cls):
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(ResourceManager, cls).__new__(cls)
return cls._instance

def __init__(self):
def __init__(self, max_workers=None):
if not self._initialized:
self.thread_pool_executor = ThreadPoolExecutor()
self.process_pool_executor = ProcessPoolExecutor()
self._max_workers = max_workers
self.thread_pool_executor = ThreadPoolExecutor(self._max_workers)
self.process_pool_executor = ProcessPoolExecutor(self._max_workers)
self.multiprocessing_manager = multiprocessing.Manager()
self._initialized = True
4 changes: 2 additions & 2 deletions agency/spaces/local_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class LocalSpace(Space):
A LocalSpace allows Agents to communicate within the python application
"""

def __init__(self):
def __init__(self, max_workers=None):
super().__init__()
self._stop_router_event: threading.Event = threading.Event()
self._outbound_message_event: multiprocessing.Event = ResourceManager(
self._outbound_message_event: multiprocessing.Event = ResourceManager(max_workers
).multiprocessing_manager.Event()
self._router_future: Future = self._start_router_thread()

Expand Down

0 comments on commit e7ff41b

Please sign in to comment.