# HG changeset patch # User Marcin Kuzminski # Date 1354230544 -3600 # Node ID 7ae9939409ab9c9586b95adec171def14b3e0d5d # Parent 12b183c1628bcbf9af7b79653920f25a45fcfa8a Use ThreadLocal storage for dulwich cached repos, finally fixes issues on concurent opening git pack files via dulwich diff -r 12b183c1628b -r 7ae9939409ab rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py Thu Nov 29 22:23:44 2012 +0100 +++ b/rhodecode/lib/vcs/backends/git/repository.py Fri Nov 30 00:09:04 2012 +0100 @@ -29,7 +29,7 @@ from rhodecode.lib.vcs.exceptions import TagAlreadyExistError from rhodecode.lib.vcs.exceptions import TagDoesNotExistError from rhodecode.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp -from rhodecode.lib.vcs.utils.lazy import LazyProperty +from rhodecode.lib.vcs.utils.lazy import LazyProperty, ThreadLocalLazyProperty from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict from rhodecode.lib.vcs.utils.paths import abspath from rhodecode.lib.vcs.utils.paths import get_user_home @@ -63,7 +63,7 @@ abspath(get_user_home(), '.gitconfig'), ] - @LazyProperty + @ThreadLocalLazyProperty def _repo(self): repo = Repo(self.path) #temporary set that to now at later we will move it to constructor diff -r 12b183c1628b -r 7ae9939409ab rhodecode/lib/vcs/utils/lazy.py --- a/rhodecode/lib/vcs/utils/lazy.py Thu Nov 29 22:23:44 2012 +0100 +++ b/rhodecode/lib/vcs/utils/lazy.py Fri Nov 30 00:09:04 2012 +0100 @@ -26,3 +26,21 @@ return self result = obj.__dict__[self.__name__] = self._func(obj) return result + +import threading + + +class ThreadLocalLazyProperty(LazyProperty): + """ + Same as above but uses thread local dict for cache storage. + """ + + def __get__(self, obj, klass=None): + if obj is None: + return self + if not hasattr(obj, '__tl_dict__'): + obj.__tl_dict__ = threading.local().__dict__ + + result = obj.__tl_dict__[self.__name__] = self._func(obj) + return result +