Skip to content

Commit

Permalink
fix: disabling logging on __del__ (#3428)
Browse files Browse the repository at this point in the history
* fix: disabling logging on __del__

* chore: adding changelog file 3428.fixed.md

* test: avoiding early exit

* feat: testing disable

* empty commit

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
germa89 and pyansys-ci-bot committed Sep 23, 2024
1 parent 2b6dd3f commit 8298793
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3428.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: disabling logging on `__del__`
8 changes: 5 additions & 3 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,8 @@ def __del__(self):
if self._cleanup:
# removing logging handlers if they are closed to avoid I/O errors
# when exiting after the logger file has been closed.
self._cleanup_loggers()
# self._cleanup_loggers()
logging.disable(logging.CRITICAL)

try:
self.exit()
Expand All @@ -2294,10 +2295,11 @@ def __del__(self):
def _cleanup_loggers(self):
"""Clean up all the loggers"""
# Detached from ``__del__`` for easier testing
if not hasattr(self, "_log"):
return # Early exit if logger has been already cleaned.
# if not hasattr(self, "_log"):
# return # Early exit if logger has been already cleaned.

logger = self._log
logger.setLevel(logging.CRITICAL + 1)

if logger.hasHandlers():
for each_handler in logger.logger.handlers:
Expand Down

0 comments on commit 8298793

Please sign in to comment.