comparison mercurial/lock.py @ 26357:6979a1369185

lock: add a method to prepare the lock for inheritance This is part of a series that will allow locks to be inherited by subprocesses in limited circumstances.
author Siddharth Agarwal <sid0@fb.com>
date Thu, 24 Sep 2015 10:37:13 -0700
parents 927fa07a2ba4
children de5a52e5eb9e
comparison
equal deleted inserted replaced
26356:927fa07a2ba4 26357:6979a1369185
156 156
157 """ 157 """
158 locker = self._readlock() 158 locker = self._readlock()
159 return self._testlock(locker) 159 return self._testlock(locker)
160 160
161 def prepinherit(self):
162 """prepare for the lock to be inherited by a Mercurial subprocess
163
164 Returns a string that will be recognized by the lock in the
165 subprocess. Communicating this string to the subprocess needs to be done
166 separately -- typically by an environment variable.
167 """
168 if not self.held:
169 raise error.LockInheritanceContractViolation(
170 'prepinherit can only be called while lock is held')
171 if self._inherited:
172 raise error.LockInheritanceContractViolation(
173 'prepinherit cannot be called while lock is already inherited')
174 if self.releasefn:
175 self.releasefn()
176 if self._parentheld:
177 lockname = self.parentlock
178 else:
179 lockname = '%s:%s' % (lock._host, self.pid)
180 self._inherited = True
181 return lockname
182
161 def release(self): 183 def release(self):
162 """release the lock and execute callback function if any 184 """release the lock and execute callback function if any
163 185
164 If the lock has been acquired multiple times, the actual release is 186 If the lock has been acquired multiple times, the actual release is
165 delayed to the last release call.""" 187 delayed to the last release call."""