import ldap
import logging
import pickle
+import threading
import time
import tornado.locale
)
class Users(base.Object):
- #def init(self):
- # self.ldap = ldap.LDAP(self.backend)
+ def init(self):
+ # Initialize thread-local storage
+ self.local = threading.local()
- @lazy_property
+ @property
def ldap(self):
- ldap_uri = self.backend.config.get("ldap", "uri")
+ if not hasattr(self.local, "ldap"):
+ # Fetch the LDAP URI
+ ldap_uri = self.backend.config.get("ldap", "uri")
+
+ log.debug("Connecting to %s..." % ldap_uri)
- log.debug("Connecting to %s..." % ldap_uri)
+ # Establish LDAP connection
+ self.local.ldap = ldap.initialize(ldap_uri)
- # Establish LDAP connection
- return ldap.initialize(ldap_uri)
+ return self.local.ldap
def _get_user(self, query, *args):
res = self.db.get(query, *args)