# HG changeset patch # User Marcin Kuzminski # Date 2012-11-29 23:09:04 # Node ID 7ae9939409ab9c9586b95adec171def14b3e0d5d # Parent 12b183c1628bcbf9af7b79653920f25a45fcfa8a Use ThreadLocal storage for dulwich cached repos, finally fixes issues on concurent opening git pack files via dulwich diff --git a/rhodecode/lib/vcs/backends/git/repository.py b/rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py +++ b/rhodecode/lib/vcs/backends/git/repository.py @@ -29,7 +29,7 @@ from rhodecode.lib.vcs.exceptions import 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 @@ class GitRepository(BaseRepository): 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 --git a/rhodecode/lib/vcs/utils/lazy.py b/rhodecode/lib/vcs/utils/lazy.py --- a/rhodecode/lib/vcs/utils/lazy.py +++ b/rhodecode/lib/vcs/utils/lazy.py @@ -26,3 +26,21 @@ class LazyProperty(object): 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 +