From 8165fa93bfd78c0f477dcf96981a5912e7fbb025 Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Thu, 23 Jul 2020 13:35:06 -0400 Subject: [PATCH] Allow customization of shutdown behavior Instead of deleting comtypes.shutdown it is made private (by renaming to comtypes._shutdown). This allows applications to unregister shutdown from atexit and call it at the appropriate time instead. It fixes crash during exit in applications that embed Python (and thus may require a custom shutdown sequence). --- comtypes/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/comtypes/__init__.py b/comtypes/__init__.py index 886e970f7..874119b26 100644 --- a/comtypes/__init__.py +++ b/comtypes/__init__.py @@ -169,7 +169,7 @@ def CoUninitialize(): _ole32_nohresult.CoUninitialize() -def shutdown(func=_ole32_nohresult.CoUninitialize, +def _shutdown(func=_ole32_nohresult.CoUninitialize, _debug=logger.debug, _exc_clear=getattr(sys, "exc_clear", lambda: None)): # Make sure no COM pointers stay in exception frames. @@ -190,8 +190,7 @@ def shutdown(func=_ole32_nohresult.CoUninitialize, _debug("CoUnititialize() done.") import atexit -atexit.register(shutdown) -del shutdown +atexit.register(_shutdown) ################################################################ # global registries.