python threading的用法:
class SearchFactory():lock = Lock()def __init__(self, server, timeout=3):self.instances = {}self.server = serverself.timeout = timeoutdef get(self, context):from models import has_modelif not has_model(context): return Noneif context in self.instances:return self.instances[context]self.lock.acquire()try:#initialize search connectionscon = Solr(self.server + context + "/", timeout=self.timeout)self.instances[context] = conreturn self.instances[context]finally:self.lock.release()
确保初始化solr正确