Skip to content

Commit

Permalink
fixing not being able to kill instance until port was already listening.
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 committed Jan 8, 2024
1 parent 28ca8c4 commit a6852aa
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/ansys/mapdl/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def stop(port, pid, all):
if port or all:
killed_ = False
for proc in psutil.process_iter():
if is_ansys_process(proc):
if psutil.pid_exists(proc.pid) and is_ansys_process(proc):

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli.py#L515-L518

Added lines #L515 - L518 were not covered by tests
# Killing "all"
if all:
try:
Expand All @@ -524,11 +524,15 @@ def stop(port, pid, all):
except psutil.NoSuchProcess:
pass

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli.py#L520-L525

Added lines #L520 - L525 were not covered by tests

# Killing by ports
for conns in proc.connections(kind="inet"):
if conns.laddr.port == port:
proc.kill()
killed_ = True
else:
# Killing by ports
if str(port) in proc.cmdline():
try:
proc.kill()
killed_ = True
except psutil.NoSuchProcess:
pass

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli.py#L529-L534

Added lines #L529 - L534 were not covered by tests

if all:
str_ = ""

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli.py#L536-L537

Added lines #L536 - L537 were not covered by tests
else:
Expand All @@ -539,7 +543,8 @@ def stop(port, pid, all):
click.style("ERROR: ", fg="red")
+ "No Ansys instances"
+ str_
+ " have been found."
+ " have been found.\n"
+ "If you are sure there are MAPDL "
)
else:
click.echo(

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli.py#L550

Added line #L550 was not covered by tests
Expand Down

0 comments on commit a6852aa

Please sign in to comment.