`
san_yun
  • 浏览: 2639340 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

python threading

 
阅读更多

python threading的用法:

 

class SearchFactory():
    lock = Lock()

    def __init__(self, server, timeout=3):
        self.instances = {}
        self.server = server
        self.timeout = timeout

    def get(self, context):
        from models import has_model

        if not has_model(context): return None

        if context in self.instances:
            return self.instances[context]

        self.lock.acquire()
        try:
            #initialize search connections
            con = Solr(self.server + context + "/", timeout=self.timeout)
            self.instances[context] = con
            return self.instances[context]
        finally:
            self.lock.release()

 

  确保初始化solr正确

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics