aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-20 19:58:06 +0000
committerGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-20 19:58:06 +0000
commit591469b1e93f72172cef13a2f0675699994d7848 (patch)
tree0c31d244d54bae467da6c3f901ceb0c401e4ea9b /tools
parentdad7070d916614b41c17f08f3a49f42964945e1d (diff)
rebaseline_server: clean up thread locks
followup to https://codereview.chromium.org/66803004/ ('rebaseline_server: improve thread locks to allow read access during updates') (SkipBuildbotRuns) R=jcgregorio@google.com Review URL: https://codereview.chromium.org/64273011 git-svn-id: http://skia.googlecode.com/svn/trunk@12323 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/svn.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/tools/svn.py b/tools/svn.py
index aac89703ad..0c1ec4fd2b 100644
--- a/tools/svn.py
+++ b/tools/svn.py
@@ -9,6 +9,7 @@ import fnmatch
import os
import re
import subprocess
+import threading
PROPERTY_MIMETYPE = 'svn:mime-type'
@@ -45,9 +46,16 @@ class Svn:
def __init__(self, directory):
"""Set up to manipulate SVN control within the given directory.
+ The resulting object is thread-safe: access to all methods is
+ synchronized (if one thread is currently executing any of its methods,
+ all other threads must wait before executing any of its methods).
+
@param directory
"""
self._directory = directory
+ # This must be a reentrant lock, so that it can be held by both
+ # _RunCommand() and (some of) the methods that call it.
+ self._rlock = threading.RLock()
def _RunCommand(self, args):
"""Run a command (from self._directory) and return stdout as a single
@@ -55,14 +63,16 @@ class Svn:
@param args a list of arguments
"""
- print 'RunCommand: %s' % args
- proc = subprocess.Popen(args, cwd=self._directory,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdout, stderr) = proc.communicate()
- if proc.returncode is not 0:
- raise Exception('command "%s" failed in dir "%s": %s' %
- (args, self._directory, stderr))
- return stdout
+ with self._rlock:
+ print 'RunCommand: %s' % args
+ proc = subprocess.Popen(args, cwd=self._directory,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdout, stderr) = proc.communicate()
+ if proc.returncode is not 0:
+ raise Exception('command "%s" failed in dir "%s": %s' %
+ (args, self._directory, stderr))
+ return stdout
def GetInfo(self):
"""Run "svn info" and return a dictionary containing its output.
@@ -167,9 +177,10 @@ class Svn:
@param property_name property_name to set for each file
@param property_value what to set the property_name to
"""
- all_files = os.listdir(self._directory)
- matching_files = sorted(fnmatch.filter(all_files, filename_pattern))
- self.SetProperty(matching_files, property_name, property_value)
+ with self._rlock:
+ all_files = os.listdir(self._directory)
+ matching_files = sorted(fnmatch.filter(all_files, filename_pattern))
+ self.SetProperty(matching_files, property_name, property_value)
def ExportBaseVersionOfFile(self, file_within_repo, dest_path):
"""Retrieves a copy of the base version (what you would get if you ran