Skip to content

Commit

Permalink
chore: Code maintenance (#937)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
dipinknair and pyansys-ci-bot authored Oct 9, 2024
1 parent a04e8be commit a4537bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/937.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code maintenance
8 changes: 6 additions & 2 deletions src/ansys/mechanical/core/embedding/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ def initialize(version: int = None):
__check_for_mechanical_env() # checks for mechanical-env in linux embedding

global INITIALIZED_VERSION
if INITIALIZED_VERSION != None:
assert INITIALIZED_VERSION == version
if INITIALIZED_VERSION is not None:
if INITIALIZED_VERSION != version:
raise ValueError(
f"Initialized version {INITIALIZED_VERSION} "
f"does not match the expected version {version}."
)
return

if version == None:
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/mechanical/core/embedding/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def _reshape_3cols(arr: np.array, name: str = "array"):
"""
err = f"{name} must be of the form (x0,y0,z0,x1,y1,z1,...,xn,yn,zn).\
Given {name} are not divisible by 3!"
assert arr.size % 3 == 0, err
if arr.size % 3 != 0:
raise ValueError(err)
numrows = int(arr.size / 3)
numcols = 3
arr = np.reshape(arr, (numrows, numcols))
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ def name(self):
return f"GRPC_{self._channel._channel._channel.target().decode()}"
else:
return f"GRPC_{self._channel._channel.target().decode()}"
except Exception: # pragma: no cover
pass
except Exception as e: # pragma: no cover
LOG.error(f"Error getting the Mechanical instance name: {str(e)}")

return f"GRPC_instance_{id(self)}" # pragma: no cover

Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ def threaded_exit(index, instance_local):
if instance_local:
try:
instance_local.exit()
except: # pragma: no cover
pass
except Exception as e: # pragma: no cover
LOG.error(f"Error while exiting instance {str(instance_local)}: {str(e)}")
self._instances[index] = None
LOG.debug(f"Exited instance: {str(instance_local)}")

Expand Down
3 changes: 2 additions & 1 deletion src/ansys/mechanical/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ async def _read_and_display(cmd, env, do_display: bool):
}
while tasks:
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
assert done
if not done:
raise RuntimeError("Subprocess read failed: No tasks completed.")
for future in done:
buf, stream, display = tasks.pop(future)
line = future.result()
Expand Down

0 comments on commit a4537bf

Please sign in to comment.