Skip to content

Commit

Permalink
suppress exceptions when closing handlers during __del__
Browse files Browse the repository at this point in the history
when `__del__` is called during process teardown, any amount of things may already be torn down and fail

currently seeing this with `typing.cast` being None, preventing access of `self.log` (or any trait) from succeeding
  • Loading branch information
minrk committed Nov 28, 2024
1 parent 9522ad6 commit 1d1e710
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion traitlets/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,11 @@ def exit(self, exit_status: int | str | None = 0) -> None:
sys.exit(exit_status)

def __del__(self) -> None:
self.close_handlers()
# __del__ may be called during process teardown,
# at which point any fraction of attributes and modules may have been cleared,
# e.g. even _accessing_ self.log may fail.
with suppress(Exception):
self.close_handlers()

@classmethod
def launch_instance(cls, argv: ArgvType = None, **kwargs: t.Any) -> None:
Expand Down

0 comments on commit 1d1e710

Please sign in to comment.