当前位置: 代码迷 >> 综合 >> python threading
  详细解决方案

python threading

热度:24   发布时间:2023-12-21 19:31:46.0

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正确