Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: git_cache.py

Issue 499003002: Do threading.Lock the Right Way. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cache.py
diff --git a/git_cache.py b/git_cache.py
index d6ed2a82d313980da46e1f0d5bd936fce043c0f5..bfdef80d797431d12a3c922a0236ff6931e4875c 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -200,25 +200,23 @@ class Mirror(object):
@classmethod
def SetCachePath(cls, cachepath):
- cls.cachepath_lock.acquire()
- setattr(cls, 'cachepath', cachepath)
- cls.cachepath_lock.release()
+ with cls.cachepath_lock:
+ setattr(cls, 'cachepath', cachepath)
@classmethod
def GetCachePath(cls):
- cls.cachepath_lock.acquire()
- if not hasattr(cls, 'cachepath'):
- try:
- cachepath = subprocess.check_output(
- [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip()
- except subprocess.CalledProcessError:
- cachepath = None
- if not cachepath:
- cls.cachepath_lock.release()
- raise RuntimeError('No global cache.cachepath git configuration found.')
- setattr(cls, 'cachepath', cachepath)
- cls.cachepath_lock.release()
- return getattr(cls, 'cachepath')
+ with cls.cachepath_lock:
+ if not hasattr(cls, 'cachepath'):
+ try:
+ cachepath = subprocess.check_output(
+ [cls.git_exe, 'config', '--global', 'cache.cachepath']).strip()
+ except subprocess.CalledProcessError:
+ cachepath = None
+ if not cachepath:
+ raise RuntimeError(
+ 'No global cache.cachepath git configuration found.')
+ setattr(cls, 'cachepath', cachepath)
+ return getattr(cls, 'cachepath')
def RunGit(self, cmd, **kwargs):
"""Run git in a subprocess."""
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698