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: not deleting temporary file when remove_temp_dir_on_exit=True #3247

Merged
merged 21 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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/3247.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: not deleting temporary file when ``remove_temp_dir_on_exit``=True
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ def launch_grpc(
proc = get_process_at_port(port)
if proc:
if is_ansys_process(proc):
raise PortAlreadyInUseByAnMAPDLInstance
raise PortAlreadyInUseByAnMAPDLInstance(port)
else:
raise PortAlreadyInUse
raise PortAlreadyInUse(port)

pymapdl._LOCAL_PORTS.append(port)

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def create_temp_dir(tmpdir=None, name=None):
if not name:
random_name = True
letters_ = string.ascii_lowercase.replace("n", "")
name = random_string(10, letters_)
name = "ansys_" + random_string(10, letters_)
else:
random_name = False

Expand Down
23 changes: 20 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 Down Expand Up @@ -2310,7 +2310,7 @@ def test_use_vtk(mapdl):


@requires("local")
def test_remove_temp_dir_on_exit(mapdl, tmpdir):
def test__remove_temp_dir_on_exit(mapdl, tmpdir):
path = os.path.join(tempfile.gettempdir(), "ansys_" + random_string())
os.makedirs(path)
filename = os.path.join(path, "file.txt")
Expand All @@ -2328,6 +2328,23 @@ def test_remove_temp_dir_on_exit(mapdl, tmpdir):
assert os.path.exists(path) is False


@requires("local")
@requires("nostudent")
def test_remove_temp_dir_on_exit(mapdl):

mapdl_2 = launch_mapdl(remove_temp_dir_on_exit=True, port=mapdl.port + 21)
germa89 marked this conversation as resolved.
Show resolved Hide resolved
path_ = mapdl_2.directory
assert os.path.exists(path_)
assert all([psutil.pid_exists(pid) for pid in mapdl_2._pids])

mapdl_2.exit()
time.sleep(1.0)
assert not os.path.exists(path_)
assert not all([psutil.pid_exists(pid) for pid in mapdl_2._pids])

# checking also pids


def test_sys(mapdl):
assert "hi" in mapdl.sys("echo 'hi'")

Expand Down
2 changes: 2 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def pool(tmpdir_factory):
exec_file=EXEC_FILE,
additional_switches=QUICK_LAUNCH_SWITCHES,
nproc=NPROC,
wait=True, # make sure that the pool is ready before testing
)
else:
port2 = os.environ.get("PYMAPDL_PORT2", 50057)
Expand All @@ -92,6 +93,7 @@ def pool(tmpdir_factory):
license_server_check=False,
start_instance=False,
port=[port, port2],
wait=True,
)

yield mapdl_pool
Expand Down
Loading