diff --git a/traitlets/config/application.py b/traitlets/config/application.py index b01a11e5..d2ba8c87 100644 --- a/traitlets/config/application.py +++ b/traitlets/config/application.py @@ -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: