Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/3736.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: improving pool testing
50 changes: 17 additions & 33 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@
self._instances: List[None] = []
self._n_instances = n_instances

# Getting debug arguments
_debug_no_launch = kwargs.get("_debug_no_launch", None)

if run_location is None:
run_location = create_temp_dir()
self._root_dir: str = run_location
Expand Down Expand Up @@ -325,17 +322,6 @@
# initialize a list of dummy instances
self._instances = [None for _ in range(n_instances)]

# threaded spawn
if _debug_no_launch:
self._debug_no_launch = {
"ports": ports,
"ips": ips,
"names": self._names,
"start_instance": start_instance,
"exec_file": exec_file,
"n_instances": n_instances,
}

# Converting ip or hostname to ip
self._ips = [socket.gethostbyname(each) for each in self._ips]
_ = [check_valid_ip(each) for each in self._ips] # double check
Expand All @@ -354,12 +340,11 @@
for i, (ip, port) in enumerate(zip(ips, ports))
]

# Early exit due to debugging
if _debug_no_launch:
return
# Storing
self._threads = threads

Check warning on line 344 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L344

Added line #L344 was not covered by tests

if wait:
[thread.join() for thread in threads]
[thread.join() for thread in self._threads]

Check warning on line 347 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L347

Added line #L347 was not covered by tests

# make sure everything is ready
n_instances_ready = 0
Expand Down Expand Up @@ -830,6 +815,7 @@
>>> pool.exit()
"""
self._active = False # kills any active instance restart
self._spawning_i = 0 # Avoid respawning

Check warning on line 818 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L818

Added line #L818 was not covered by tests

@threaded
def threaded_exit(index, instance):
Expand All @@ -842,7 +828,7 @@
f"Unable to exit instance {index} because of the following reason:\n{str(e)}"
)
self._instances[index] = None
# LOG.debug("Exited instance: %s", str(instance))
LOG.debug(f"Exited instance: {instance}")

Check warning on line 831 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L831

Added line #L831 was not covered by tests
self._exiting_i -= 1

threads = []
Expand Down Expand Up @@ -907,9 +893,6 @@
if not run_location:
run_location = create_temp_dir(self._root_dir, name=name)

if self._spawn_kwargs.get("_debug_no_launch", False):
return

self._instances[index] = launch_mapdl(
exec_file=exec_file,
run_location=run_location,
Expand All @@ -925,21 +908,12 @@
# This is introduce to mitigate #2173
timeout = time.time() + timeout

def initialized(index):
if self._instances[index] is not None:
if self._instances[index].exited:
raise MapdlRuntimeError("The instance is already exited!")
if "PREP" not in self._instances[index].prep7().upper():
raise MapdlDidNotStart("Error while processing PREP7 signal.")
return True
return False

while timeout > time.time():
if initialized(index):
if self.is_initialized(index):

Check warning on line 912 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L912

Added line #L912 was not covered by tests
break
time.sleep(0.1)
else:
if not initialized:
if not self.is_initialized(index):

Check warning on line 916 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L916

Added line #L916 was not covered by tests
raise TimeoutError(
f"The instance running at {ip}:{port} could not be started."
)
Expand All @@ -950,6 +924,16 @@

self._spawning_i -= 1

def is_initialized(self, index):
"""Check if the instance is initialized"""
if self._instances[index] is not None:
if self._instances[index].exited:
raise MapdlRuntimeError("The instance is already exited!")
if "PREP" not in self._instances[index].prep7().upper():
raise MapdlDidNotStart("Error while processing PREP7 signal.")
return True
return False

Check warning on line 935 in src/ansys/mapdl/core/pool.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/pool.py#L929-L935

Added lines #L929 - L935 were not covered by tests

@threaded_daemon
def _monitor_pool(self, refresh=1.0):
"""Checks if instances within a pool have exited (failed) and
Expand Down
Loading