Set the ldap.OPT_NETWORK_TIMEOUT option to the ldap object.
import ldap l = ldap.initialize('ldap://servername:389') l.set_option(ldap.OPT_NETWORK_TIMEOUT, 10.0) l.simple_bind_s('username', 'password')
This will throw an ldap.SERVER_DOWN exception if the specified timeout is reached.
source share