Skip to content

Commit 7037b06

Browse files
authored
Make public (again) the create and close APIs in local_worker_manager (#457)
They were made "internal" unnecessarily (by the convention of the `_` prefix) in PR #453
1 parent 5f6e9b3 commit 7037b06

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compiler_opt/distributed/local/local_worker_manager.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ def __dir__(self):
254254
return _Stub()
255255

256256

257-
def _create_local_worker_pool(worker_cls: 'type[worker.Worker]',
258-
count: int | None, parse_argv: bool, pickle_func,
259-
*args, **kwargs) -> worker.FixedWorkerPool:
257+
# The following pair of APIs - create and close - are public without having
258+
# a user to support out-of-repo scenarios.
259+
def create_local_worker_pool(worker_cls: 'type[worker.Worker]',
260+
count: int | None, parse_argv: bool, pickle_func,
261+
*args, **kwargs) -> worker.FixedWorkerPool:
260262
"""Create a local worker pool for worker_cls."""
261263
if not count:
262264
count = _get_context().cpu_count()
@@ -268,7 +270,7 @@ def _create_local_worker_pool(worker_cls: 'type[worker.Worker]',
268270
return worker.FixedWorkerPool(workers=stubs, worker_concurrency=16)
269271

270272

271-
def _close_local_worker_pool(pool: worker.FixedWorkerPool):
273+
def close_local_worker_pool(pool: worker.FixedWorkerPool):
272274
"""Close the given LocalWorkerPool."""
273275
# first, trigger killing the worker process and exiting of the msg pump,
274276
# which will also clear out any pending futures.
@@ -290,15 +292,15 @@ def __init__(self,
290292
worker_args: tuple = (),
291293
worker_kwargs: dict | None = None):
292294
worker_kwargs = {} if worker_kwargs is None else worker_kwargs
293-
self._pool = _create_local_worker_pool(worker_class, count, True,
294-
pickle_func, *worker_args,
295-
**worker_kwargs)
295+
self._pool = create_local_worker_pool(worker_class, count, True,
296+
pickle_func, *worker_args,
297+
**worker_kwargs)
296298

297299
def __enter__(self) -> worker.FixedWorkerPool:
298300
return self._pool
299301

300302
def __exit__(self, *args):
301-
_close_local_worker_pool(self._pool)
303+
close_local_worker_pool(self._pool)
302304

303305
def __del__(self):
304306
self.__exit__()

0 commit comments

Comments
 (0)