Skip to content

Commit

Permalink
suppress exceptions when closing handlers during __del__ (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk authored Feb 4, 2025
1 parent 1805ad9 commit 5bacf10
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 5bacf10

Please sign in to comment.