def reconnect(self,uri,retry_max=1,retry_delay=60.0):
# Drop and clean up old connection completely
# Reconnect
self._reconnect_lock.acquire()
try:
reconnect_counter = retry_max
while reconnect_counter:
counter_text = '%d. (of %d)' % (retry_max-reconnect_counter+1,retry_max)
if __debug__ and self._trace_level>=1:
self._trace_file.write('*** Trying %s reconnect to %s...\n' % (
counter_text,uri
))
try:
# Do the connect
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
self._restore_options()
# StartTLS extended operation in case this was called before
if self._start_tls:
SimpleLDAPObject.start_tls_s(self)
# Repeat last simple or SASL bind
self._apply_last_bind()
except (ldap.SERVER_DOWN,ldap.TIMEOUT):
if __debug__ and self._trace_level>=1:
self._trace_file.write('*** %s reconnect to %s failed\n' % (
counter_text,uri
))
reconnect_counter = reconnect_counter-1
if not reconnect_counter:
raise
if __debug__ and self._trace_level>=1:
self._trace_file.write('=> delay %s...\n' % (retry_delay))
time.sleep(retry_delay)
SimpleLDAPObject.unbind_s(self)
del self._l
else:
if __debug__ and self._trace_level>=1:
self._trace_file.write('*** %s reconnect to %s successful => repeat last operation\n' % (
counter_text,uri
))
self._reconnects_done = self._reconnects_done + 1
break
finally:
self._reconnect_lock.release()
return # reconnect()
评论列表
文章目录