Skip to content

Commit

Permalink
Added create key
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishA26 committed Jul 4, 2024
1 parent 8acde34 commit c7bcd46
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions utilities/workers/worker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ class WorkerManager:
Contains exit and pause requests.
"""

def __init__(
self,
workers: "list[mp.Process]",
) -> None:
"""
Constructor.
"""
self.__workers = workers
__create_key = object()

@classmethod
def create(
Expand All @@ -47,7 +40,6 @@ def create(
Returns whether the workers were able to be created and the Worker Manager.
"""

result, worker_manager_logger = logger.Logger.create("worker_manager")
if not result:
print("Error creating worker manager logger")
Expand All @@ -58,7 +50,10 @@ def create(

if count <= 0:
frame = inspect.currentframe()
worker_manager_logger.error("Worker count requested is less than or equal to zero, no workers were created", frame)
worker_manager_logger.error(
"Worker count requested is less than or equal to zero, no workers were created",
frame,
)
return False, None

args = WorkerManager.__create_worker_arguments(
Expand All @@ -67,7 +62,11 @@ def create(

workers = []
for _ in range(0, count):
result, worker = WorkerManager.__create_single_worker(target, args, worker_manager_logger)
result, worker = WorkerManager.__create_single_worker(
target,
args,
worker_manager_logger,
)
if not result:
frame = inspect.currentframe()
worker_manager_logger.error("Failed to create worker", frame)
Expand All @@ -76,9 +75,22 @@ def create(
workers.append(worker)

return True, WorkerManager(
cls.__create_key,
workers,
)

def __init__(
self,
class_private_create_key: object,
workers: "list[mp.Process]",
) -> None:
"""
Private constructor, use create() method.
"""
assert class_private_create_key is WorkerManager.__create_key, "Use create() method"

self.__workers = workers

@staticmethod
def __create_worker_arguments(
class_args: "tuple",
Expand Down

0 comments on commit c7bcd46

Please sign in to comment.