From 79ecdc11f2620dc1b83ffa2eaefc77350c18bd12 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:23:27 +0100 Subject: [PATCH] Allowing only one worker in pool (#2656) * As the title. * removing f from string * Adding unit tests --- src/ansys/mapdl/core/pool.py | 6 +++--- tests/test_pool.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/ansys/mapdl/core/pool.py b/src/ansys/mapdl/core/pool.py index e33ffb5fb9..7bf540916d 100755 --- a/src/ansys/mapdl/core/pool.py +++ b/src/ansys/mapdl/core/pool.py @@ -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'." ) diff --git a/tests/test_pool.py b/tests/test_pool.py index bbbaff50c6..93370ed82a 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -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()