Skip to content

Commit

Permalink
Allowing only one worker in pool (#2656)
Browse files Browse the repository at this point in the history
* As the title.

* removing f from string

* Adding unit tests
  • Loading branch information
germa89 authored Jan 12, 2024
1 parent 6495bda commit 79ecdc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def __init__(
self._active = True # used by pool monitor

n_instances = int(n_instances)
if n_instances < 2:
raise ValueError("Must request at least 2 instances to create a pool.")
if n_instances < 1:
raise ValueError("Must request at least 1 instance to create a pool.")

pbar = None
if wait and progress_bar:
if not _HAS_TQDM: # pragma: no cover
raise ModuleNotFoundError(
f"To use the keyword argument 'progress_bar', you need to have installed the 'tqdm' package. "
"To use the keyword argument 'progress_bar', you need to have installed the 'tqdm' package. "
"To avoid this message you can set 'progress_bar=False'."
)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,28 @@ def myfun(i):
assert "Other_instance" in dirs_path_pool

pool.exit(block=True)


def test_num_instances():
with pytest.raises(ValueError, match="least 1 instance"):
pool = LocalMapdlPool(
0,
exec_file=EXEC_FILE,
nproc=NPROC,
additional_switches=QUICK_LAUNCH_SWITCHES,
)


@requires("local")
@skip_if_ignore_pool
def test_only_one_instance():
pool = LocalMapdlPool(
1,
exec_file=EXEC_FILE,
nproc=NPROC,
additional_switches=QUICK_LAUNCH_SWITCHES,
)
pool_sz = len(pool)
_ = pool.map(lambda mapdl: mapdl.prep7())
assert len(pool) == pool_sz
pool.exit()

0 comments on commit 79ecdc1

Please sign in to comment.