Skip to content

Commit 1d1e710

Browse files
committed
suppress exceptions when closing handlers during __del__
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
1 parent 9522ad6 commit 1d1e710

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

traitlets/config/application.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,11 @@ def exit(self, exit_status: int | str | None = 0) -> None:
10621062
sys.exit(exit_status)
10631063

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

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

0 commit comments

Comments
 (0)