Patchwork [4,of,5] lock: add a method to reacquire the lock after subprocesses exit

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 24, 2015, 11:29 p.m.
Message ID <ba556998f3d950a16bd8.1443137379@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10620/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 24, 2015, 11:29 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1443135641 25200
#      Thu Sep 24 16:00:41 2015 -0700
# Node ID ba556998f3d950a16bd890a1d7f23ba8cdb6801c
# Parent  a5358efa5b11aa4fe97bd91951a68dcaa84e6d15
lock: add a method to reacquire the lock after subprocesses exit

This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.

Patch

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -180,6 +180,14 @@  class lock(object):
         self._inherited = True
         return lockname
 
+    def reacquire(self):
+        if not self._inherited:
+            raise error.LockInheritanceContractViolation(
+                'reacquire can only be called after prepinherit')
+        if self.acquirefn:
+            self.acquirefn()
+        self._inherited = False
+
     def release(self):
         """release the lock and execute callback function if any