[damned-lies] Moved locking around to prevent deadlock



commit 04e34fbce634c55d1009365605f17d3b5c340700
Author: Claude Paroz <claude 2xlibre net>
Date:   Sun Oct 18 00:07:59 2015 +0200

    Moved locking around to prevent deadlock

 stats/models.py |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 35c5b06..7805e34 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -222,8 +222,9 @@ class Branch(models.Model):
     def clean(self):
         if self.checkout_on_creation and not self.module.archived:
             try:
-                self.checkout()
-            except:
+                with ModuleLock(self.module):
+                    self.checkout()
+            except Exception:
                 raise ValidationError("Branch not valid: error while checking out the branch (%s)." % 
sys.exc_info()[1])
 
     def save(self, update_statistics=True, **kwargs):
@@ -248,8 +249,9 @@ class Branch(models.Model):
                     shutil.rmtree(self.co_path())
             else:
                 wd = self.co_path()
-                utils.run_shell_command(['git', 'checkout', 'master'], cwd=wd)
-                utils.run_shell_command(['git', 'branch', '-D', self.name], cwd=wd)
+                with ModuleLock(self.module):
+                    utils.run_shell_command(['git', 'checkout', 'master'], cwd=wd)
+                    utils.run_shell_command(['git', 'branch', '-D', self.name], cwd=wd)
         #To be implemented for hg/bzr
 
         # Remove the pot/po generated files
@@ -617,17 +619,14 @@ class Branch(models.Model):
 
         # Run command(s)
         logging.debug("Checking '%s.%s' out to '%s'..." % (module_name, self.name, modulepath))
-        # Do not allow 2 checkouts to run in parallel on the same branch
-        with ModuleLock(self.module):
-            for working_dir, command in command_list:
-                utils.run_shell_command(command, raise_on_error=True, cwd=working_dir)
-        return 1
+        for working_dir, command in command_list:
+            utils.run_shell_command(command, raise_on_error=True, cwd=working_dir)
 
     def update_repo(self, execute=True):
         """
         Update existing repository checkout.
-        WARNING: the calling method should acquire a lock for the module to not
-        mix checkouts in different threads/processes.
+        WARNING: if execute is True, the calling method should acquire a lock
+        for the module to not mix checkouts in different threads/processes.
         """
         modulepath = self.co_path()
         logging.debug("Updating '%s.%s' (in '%s')..." % (self.module.name, self.name, modulepath))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]