From 27d771c0b65d0af5a7b3d38534a6c447a4098f5f Mon Sep 17 00:00:00 2001 From: German Date: Fri, 4 Mar 2022 15:51:12 +0100 Subject: [PATCH 1/3] Remove previous temporal files. --- src/ansys/mapdl/core/mapdl_grpc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 01054908460..14bd537a4c9 100755 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1236,6 +1236,7 @@ def input( # file. tmp_name = "_input_tmp_.inp" tmp_out = "_input_tmp_.out" + if "CDRE" in orig_cmd.upper(): # Using CDREAD option = kwargs.get("cd_read_option", "COMB") @@ -1245,11 +1246,27 @@ def input( tmp_dat = f"/OUT,{tmp_out}\n{orig_cmd},'{filename}'\n" if self._local: + # delete the files to avoid overwriting: + try: + os.remove(tmp_name) + except OSError: # pragma: no cover + pass + + try: + os.remove(tmp_out) # pragma: no cover + except OSError: + pass + local_path = self.directory with open(os.path.join(local_path, tmp_name), "w") as f: f.write(tmp_dat) else: + # Deleting the previous files + self.slashdelete(tmp_name) + self.slashdelete(tmp_out) + self._upload_raw(tmp_dat.encode(), tmp_name) + request = pb_types.InputFileRequest(filename=tmp_name) # even though we don't care about the output, we still From 06f21b457ef119b4dfc6f4cb2be3244beaae2045 Mon Sep 17 00:00:00 2001 From: German Date: Fri, 4 Mar 2022 15:56:03 +0100 Subject: [PATCH 2/3] Removing at the end of the input call. --- src/ansys/mapdl/core/mapdl_grpc.py | 37 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 14bd537a4c9..44807936c7a 100755 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1246,25 +1246,10 @@ def input( tmp_dat = f"/OUT,{tmp_out}\n{orig_cmd},'{filename}'\n" if self._local: - # delete the files to avoid overwriting: - try: - os.remove(tmp_name) - except OSError: # pragma: no cover - pass - - try: - os.remove(tmp_out) # pragma: no cover - except OSError: - pass - local_path = self.directory with open(os.path.join(local_path, tmp_name), "w") as f: f.write(tmp_dat) else: - # Deleting the previous files - self.slashdelete(tmp_name) - self.slashdelete(tmp_out) - self._upload_raw(tmp_dat.encode(), tmp_name) request = pb_types.InputFileRequest(filename=tmp_name) @@ -1278,10 +1263,28 @@ def input( # all output (unless redirected) has been written to a temp output if self._local: with open(os.path.join(local_path, tmp_out)) as f: - return f.read() + output = f.read() + + # delete the files to avoid overwriting: + try: + os.remove(tmp_name) + except OSError: # pragma: no cover + pass + + try: + os.remove(tmp_out) # pragma: no cover + except OSError: + pass # otherwise, read remote file - return self._download_as_raw(tmp_out).decode("latin-1") + else: + output = self._download_as_raw(tmp_out).decode("latin-1") + + # Deleting the previous files + self.slashdelete(tmp_name) + self.slashdelete(tmp_out) + + return output def _get_file_path(self, fname, progress_bar=False): """Find files in the Python and MAPDL working directories. From d84d48c9de2dcc486eab9ecbfde1b999a7c9877b Mon Sep 17 00:00:00 2001 From: German Date: Fri, 4 Mar 2022 16:35:48 +0100 Subject: [PATCH 3/3] Not covering local case --- src/ansys/mapdl/core/mapdl_grpc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 44807936c7a..eb7dec79b4b 100755 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1261,18 +1261,18 @@ def input( _ = [chunk.cmdout for chunk in chunks] # unstable # all output (unless redirected) has been written to a temp output - if self._local: + if self._local: # pragma: no cover with open(os.path.join(local_path, tmp_out)) as f: output = f.read() # delete the files to avoid overwriting: try: os.remove(tmp_name) - except OSError: # pragma: no cover + except OSError: pass try: - os.remove(tmp_out) # pragma: no cover + os.remove(tmp_out) except OSError: pass