Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pool issues #3266

Merged
merged 66 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
53ef4e6
feat: adding port to exception message
germa89 Jul 8, 2024
c38b6de
fix: attempt tests before being ready
germa89 Jul 8, 2024
f4ec8c0
feat: changing arguments order
germa89 Jul 8, 2024
699d83d
Merge branch 'main' into fix/tests
germa89 Jul 9, 2024
325a67f
chore: wait for complete exit
germa89 Jul 9, 2024
dc0f3ed
test: raise exception if mapdl instances are alive between tests
germa89 Jul 9, 2024
a5f36f5
chore: adding changelog file 3257.added.md
pyansys-ci-bot Jul 9, 2024
bd50f30
fix: adding missing import
germa89 Jul 9, 2024
f4d36f6
fix: adding missing object
germa89 Jul 9, 2024
3c39186
test: check process status
germa89 Jul 9, 2024
f474c23
fix: running process check only on local.
germa89 Jul 9, 2024
9f207d8
feat: enforcing having exactly the amount of instances specified.
germa89 Jul 10, 2024
8a7ca1d
Merge branch 'main' into feat/checking-no-instances-are-left-after-ea…
germa89 Jul 10, 2024
a624ba7
feat: adding a timeout before moving on
germa89 Jul 10, 2024
2927617
Merge branch 'main' into fix/pool-issues
germa89 Jul 10, 2024
ff6a664
fix: latest_version env var
germa89 Jul 10, 2024
9c6e5c3
feat: added pool_creator fixture. We use pool fixture to check pool h…
germa89 Jul 10, 2024
bd70a43
fix: NoSuchProcess error. Small cosmetic fix
germa89 Jul 10, 2024
bede253
chore: adding changelog file 3266.fixed.md
pyansys-ci-bot Jul 10, 2024
641c38d
chore: adding changelog file 3266.fixed.md
pyansys-ci-bot Jul 10, 2024
dcc2a39
refactor: small reog
germa89 Jul 10, 2024
dd8ff32
test: activating previously skipped tests
germa89 Jul 10, 2024
6412c46
fix: test
germa89 Jul 10, 2024
f4b34d0
fix: adding port to avoid port collision
germa89 Jul 10, 2024
d58971b
fkix: tests
germa89 Jul 10, 2024
bef97e8
Merge branch 'main' into feat/checking-no-instances-are-left-after-ea…
germa89 Jul 10, 2024
c6d49f1
docs: adding comments
germa89 Jul 10, 2024
1e63bb4
Merge branch 'feat/checking-no-instances-are-left-after-each-test' in…
germa89 Jul 10, 2024
f5870a6
feat: adding ``ready`` property and ``wait_for_ready`` method.
germa89 Jul 11, 2024
24325d5
feat: Checking ports from the cmdline
germa89 Jul 11, 2024
e81a6c5
fix: tests
germa89 Jul 11, 2024
8c7e58b
fix: early exit in process check to avoid accessdenied.
germa89 Jul 11, 2024
129469c
Revert "fkix: tests"
germa89 Jul 11, 2024
7fb035b
feat: catching already dead process.
germa89 Jul 11, 2024
5804c4a
fix: pymapdl list not showing any instance because name method wasn't…
germa89 Jul 11, 2024
f9ff25c
feat: wrapping process checking in a try/except to avoid calling alre…
germa89 Jul 11, 2024
aa9f372
feat: using dynamic port in test_cli. Starting and stopping another i…
germa89 Jul 11, 2024
eaeec0d
Merge branch 'main' into fix/pool-issues
germa89 Jul 11, 2024
6fe4991
fix: test
germa89 Jul 11, 2024
06e117f
refactor: reducing code duplicity
germa89 Jul 11, 2024
1c06fe3
feat: making sure we stop MAPDL if failure
germa89 Jul 11, 2024
7d39555
fix: test_remove_temp_dir_on_exit on windows
germa89 Jul 11, 2024
d2ba656
test: without rerun
germa89 Jul 11, 2024
df12fbe
ci: using v24.2 for docs building
germa89 Jul 11, 2024
5e65c89
fix: exception in list instance processing
germa89 Jul 11, 2024
088b9c1
Merge branch 'fix/pool-issues' of https://github.com/ansys/pymapdl in…
germa89 Jul 11, 2024
0b8ce47
feat: using PORT1 variable
germa89 Jul 11, 2024
8d6c73b
fix: tests
germa89 Jul 11, 2024
7b86321
ci: run all tests
germa89 Jul 11, 2024
8316ba9
test: testing
germa89 Jul 11, 2024
ee42877
test: no raise exception.
germa89 Jul 12, 2024
5cf3eac
ci: increasing timeout for local and min jobs
germa89 Jul 12, 2024
17ade8a
chore: adding logging statements.
germa89 Jul 12, 2024
3604c40
test: marking tests as xfail
germa89 Jul 12, 2024
1c8a143
ci: adding back pytest config
germa89 Jul 12, 2024
726d464
Revert "build: update ansys-api-mapdl to 0.5.2 (#3255)"
germa89 Jul 12, 2024
db48bdc
test: skip flaky tests
germa89 Jul 12, 2024
f06db96
build: update ansys-api-mapdl to 0.5.2 (#3255)
germa89 Jul 9, 2024
d99d916
test: skip flaky test. See #2435 comment
germa89 Jul 12, 2024
bc2d257
fix: not showing instances on linux (#3263)
germa89 Jul 12, 2024
0a31b4a
ci: undo some stuff
germa89 Jul 12, 2024
44143a1
test: adding some waiting time after attempting to kill instance.
germa89 Jul 12, 2024
7e787ac
Merge branch 'fix/pool-issues' of https://github.com/ansys/pymapdl in…
germa89 Jul 12, 2024
abd8d7b
Merge branch 'main' into fix/pool-issues
germa89 Jul 12, 2024
2140864
fix: missing import.
germa89 Jul 12, 2024
1dda326
chore: remove fragment from other PR.
germa89 Jul 12, 2024
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
4 changes: 4 additions & 0 deletions .ci/build_matrix.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# **** REMEMBER *****
# Remember to update the env var ``LATEST_VERSION`` in ci.yml
#

# List of versions
versions=(
# if added more "latest", change "$LATEST"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ env:
PACKAGE_NAME: 'ansys-mapdl-core'
PACKAGE_NAMESPACE: 'ansys.mapdl.core'
DOCUMENTATION_CNAME: 'mapdl.docs.pyansys.com'
LATEST_VERSION: "242"
MAPDL_IMAGE_VERSION_DOCS_BUILD: v24.2-ubuntu-student
MEILISEARCH_API_KEY: ${{ secrets.MEILISEARCH_API_KEY }}
MEILISEARCH_PUBLIC_API_KEY: ${{ secrets.MEILISEARCH_PUBLIC_API_KEY }}
PYANSYS_OFF_SCREEN: True
DPF_START_SERVER: False
DPF_PORT: 21004
MAPDL_PACKAGE: ghcr.io/ansys/mapdl
MAPDL_IMAGE_VERSION_DOCS_BUILD: v24.1-ubuntu-student
ON_CI: True
PYTEST_ARGUMENTS: '-vvv -ra --durations=10 --maxfail=3 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html'

Expand Down Expand Up @@ -807,7 +808,7 @@ jobs:
# executable path with the env var: PYMAPDL_MAPDL_EXEC.

if [[ "${{ matrix.mapdl-version }}" == *"latest-ubuntu"* ]] ; then
version="242"
version=${{ env.LATEST_VERSION }}
else
version=$(echo "${{ matrix.mapdl-version }}" | head -c 5 | tail -c 4 | tr -d '.')
fi;
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3266.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: pool issues
30 changes: 21 additions & 9 deletions src/ansys/mapdl/core/cli/list_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,35 @@
mapdl_instances = []

def is_valid_process(proc):
valid_status = proc.status in [psutil.STATUS_RUNNING, psutil.STATUS_IDLE]
valid_status = proc.status() in [

Check warning on line 76 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L76

Added line #L76 was not covered by tests
psutil.STATUS_RUNNING,
psutil.STATUS_IDLE,
psutil.STATUS_SLEEPING,
]
valid_ansys_process = ("ansys" in proc.name().lower()) or (
"mapdl" in proc.name().lower()
)
# Early exit to avoid checking 'cmdline' of a protected process (raises psutil.AccessDenied)
if not valid_ansys_process:
return False

Check warning on line 86 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L85-L86

Added lines #L85 - L86 were not covered by tests

grpc_is_active = "-grpc" in proc.cmdline()
return valid_status and valid_ansys_process and grpc_is_active

for proc in psutil.process_iter():
# Check if the process is running and not suspended
if is_valid_process(proc):
# Checking the number of children we infer if the process is the main process,
# or one of the main process thread.
if len(proc.children(recursive=True)) < 2:
proc.ansys_instance = False
else:
proc.ansys_instance = True
mapdl_instances.append(proc)
try:
if is_valid_process(proc):

Check warning on line 94 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L93-L94

Added lines #L93 - L94 were not covered by tests
# Checking the number of children we infer if the process is the main process,
# or one of the main process thread.
if len(proc.children(recursive=True)) < 2:
proc.ansys_instance = False

Check warning on line 98 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L97-L98

Added lines #L97 - L98 were not covered by tests
else:
proc.ansys_instance = True
mapdl_instances.append(proc)

Check warning on line 101 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L100-L101

Added lines #L100 - L101 were not covered by tests

except (psutil.NoSuchProcess, psutil.ZombieProcess) as e:
continue

Check warning on line 104 in src/ansys/mapdl/core/cli/list_instances.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/list_instances.py#L103-L104

Added lines #L103 - L104 were not covered by tests

# printing
table = []
Expand Down
44 changes: 22 additions & 22 deletions src/ansys/mapdl/core/cli/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
import click


def is_ansys_process(proc):
return (
"ansys" in proc.name().lower() or "mapdl" in proc.name().lower()
) and "-grpc" in proc.cmdline()


@click.command(
short_help="Stop MAPDL instances.",
help="""This command stop MAPDL instances running on a given port or with a given process id (PID).
Expand Down Expand Up @@ -58,6 +52,8 @@
def stop(port, pid, all):
import psutil

from ansys.mapdl.core.launcher import is_ansys_process

Check warning on line 55 in src/ansys/mapdl/core/cli/stop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/stop.py#L55

Added line #L55 was not covered by tests

PROCESS_OK_STATUS = [
# List of all process status, comment out the ones that means that
# process is not OK.
Expand All @@ -84,28 +80,32 @@
if port or all:
killed_ = False
for proc in psutil.process_iter():
if (
psutil.pid_exists(proc.pid)
and proc.status() in PROCESS_OK_STATUS
and is_ansys_process(proc)
):
# Killing "all"
if all:
try:
proc.kill()
killed_ = True
except psutil.NoSuchProcess:
pass

else:
# Killing by ports
if str(port) in proc.cmdline():
try:
if (

Check warning on line 84 in src/ansys/mapdl/core/cli/stop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/stop.py#L83-L84

Added lines #L83 - L84 were not covered by tests
psutil.pid_exists(proc.pid)
and proc.status() in PROCESS_OK_STATUS
and is_ansys_process(proc)
):
# Killing "all"
if all:

Check warning on line 90 in src/ansys/mapdl/core/cli/stop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/stop.py#L90

Added line #L90 was not covered by tests
try:
proc.kill()
killed_ = True
except psutil.NoSuchProcess:
pass

else:
# Killing by ports
if str(port) in proc.cmdline():
try:
proc.kill()
killed_ = True
except psutil.NoSuchProcess:
pass

Check warning on line 104 in src/ansys/mapdl/core/cli/stop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/stop.py#L99-L104

Added lines #L99 - L104 were not covered by tests

except psutil.NoSuchProcess:
continue

Check warning on line 107 in src/ansys/mapdl/core/cli/stop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/stop.py#L106-L107

Added lines #L106 - L107 were not covered by tests

if all:
str_ = ""
else:
Expand Down
3 changes: 3 additions & 0 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def get_process_at_port(port) -> Optional[psutil.Process]:
) # just to check if we can access the
except psutil.AccessDenied:
continue
except psutil.NoSuchProcess:
# process already died
continue

for conns in connections:
if conns.laddr.port == port:
Expand Down
7 changes: 5 additions & 2 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,12 @@ def _remove_temp_dir_on_exit(self, path=None):

"""
if self.remove_temp_dir_on_exit and self._local:
path = path or self.directory
from pathlib import Path

path = str(Path(path or self.directory))
tmp_dir = tempfile.gettempdir()
ans_temp_dir = os.path.join(tmp_dir, "ansys_")
ans_temp_dir = str(Path(os.path.join(tmp_dir, "ansys_")))

if path.startswith(ans_temp_dir):
self._log.debug("Removing the MAPDL temporary directory %s", path)
shutil.rmtree(path, ignore_errors=True)
Expand Down
Loading
Loading