Best way to disconnect from ldap?

Michael Ströder michael at stroeder.com
Thu Apr 5 14:56:27 EDT 2012


John Gordon wrote:
>     class ldap.LDAPObject
>         Instances of LDAPObject are returned by initialize() and open()
>         (deprecated).  The connection is automatically unbound and closed
>         when the LDAP object is deleted.
> 
> So, given that, do I need to do anything at all?

Hmm, maybe the author of this statement (have to check who) did not know about
the caveats with __del__() when this was written ages ago. IIRC first
python-ldap release was for Python 1.4 back in '98. See use of dealloc() in
Modules/LDAPObject.c.

So I'd recommend to use the modern with-statement to make sure
LDAPObject.unbind_s() is really called. Being old-fashioned I used
try-finally-blocks until now.

Ciao, Michael.



More information about the Python-list mailing list