From 08dc22b75095222163eca59df0dd261a24f8eee4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 17 May 2019 15:25:46 +0200 Subject: [PATCH] Fix funky errors by explicitly destroying the global variable at exit time --- src/yunohost/utils/ldap.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/yunohost/utils/ldap.py b/src/yunohost/utils/ldap.py index f4a5f355c..186cdbdec 100644 --- a/src/yunohost/utils/ldap.py +++ b/src/yunohost/utils/ldap.py @@ -19,6 +19,7 @@ """ +import atexit from moulinette.core import init_authenticator # We use a global variable to do some caching @@ -38,3 +39,14 @@ def _get_ldap_interface(): _ldap_interface = init_authenticator(AUTH_IDENTIFIER, AUTH_PARAMETERS) return _ldap_interface + +# Add this to properly close / delete the ldap interface / authenticator +# when Python exits ... +# Otherwise there's a risk that some funky error appears at the very end +# of the command due to Python stuff being unallocated in wrong order. +def _destroy_ldap_interface(): + global _ldap_interface + if _ldap_interface is not None: + del _ldap_interface + +atexit.register(_destroy_ldap_interface)