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: avoid inspecting suspended processes #3227

Merged
merged 13 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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/3227.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: avoid inspecting suspended processes
16 changes: 13 additions & 3 deletions src/ansys/mapdl/core/cli/list_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,20 @@

# Assuming all ansys processes have -grpc flag
mapdl_instances = []

def is_valid_process(proc):
valid_status = proc.status in [psutil.STATUS_RUNNING, psutil.STATUS_IDLE]
valid_ansys_process = ("ansys" in proc.name().lower()) or (

Check warning on line 77 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#L75-L77

Added lines #L75 - L77 were not covered by tests
"mapdl" in proc.name().lower()
)
grpc_is_active = "-grpc" in proc.cmdline()
return valid_status and valid_ansys_process and grpc_is_active

Check warning on line 81 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#L80-L81

Added lines #L80 - L81 were not covered by tests

for proc in psutil.process_iter():
if (
"ansys" in proc.name().lower() or "mapdl" in proc.name().lower()
) and "-grpc" in proc.cmdline():
# Check if the process is running and not suspended
if is_valid_process(proc):

Check warning on line 85 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

Added line #L85 was 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
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(
license_server_check=False,
additional_switches=QUICK_LAUNCH_SWITCHES,
port=mapdl.port + 1,
port=mapdl.port + 2,
)
mapdl2.parameters["my_par"] = "initial_value"

Expand All @@ -1969,7 +1969,7 @@ def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(
license_server_check=False,
additional_switches=QUICK_LAUNCH_SWITCHES,
port=mapdl.port + 1,
port=mapdl.port + 2,
)
mapdl2.resume(db_path)
if mapdl.version >= 24.2:
Expand All @@ -1988,7 +1988,7 @@ def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(
license_server_check=False,
additional_switches=QUICK_LAUNCH_SWITCHES,
port=mapdl.port + 1,
port=mapdl.port + 2,
)
mapdl2.resume(db_path)
assert mapdl2.parameters["my_par"] == "new_initial_value"
Expand Down
Loading