mercurial/lock.py
changeset 37123 a8a902d7176e
parent 36724 d77c3b023393
child 37658 34758397ad1b
equal deleted inserted replaced
37122:d4a2e0d5d042 37123:a8a902d7176e
    19 
    19 
    20 from . import (
    20 from . import (
    21     encoding,
    21     encoding,
    22     error,
    22     error,
    23     pycompat,
    23     pycompat,
    24     util,
    24 )
       
    25 
       
    26 from .utils import (
       
    27     procutil,
    25 )
    28 )
    26 
    29 
    27 def _getlockprefix():
    30 def _getlockprefix():
    28     """Return a string which is used to differentiate pid namespaces
    31     """Return a string which is used to differentiate pid namespaces
    29 
    32 
   210             self.held = 1
   213             self.held = 1
   211 
   214 
   212         self.release()
   215         self.release()
   213 
   216 
   214     def _getpid(self):
   217     def _getpid(self):
   215         # wrapper around util.getpid() to make testing easier
   218         # wrapper around procutil.getpid() to make testing easier
   216         return util.getpid()
   219         return procutil.getpid()
   217 
   220 
   218     def lock(self):
   221     def lock(self):
   219         timeout = self.timeout
   222         timeout = self.timeout
   220         while True:
   223         while True:
   221             try:
   224             try:
   297             return locker
   300             return locker
   298         try:
   301         try:
   299             pid = int(pid)
   302             pid = int(pid)
   300         except ValueError:
   303         except ValueError:
   301             return locker
   304             return locker
   302         if util.testpid(pid):
   305         if procutil.testpid(pid):
   303             return locker
   306             return locker
   304         # if locker dead, break lock.  must do this with another lock
   307         # if locker dead, break lock.  must do this with another lock
   305         # held, or can race and break valid lock.
   308         # held, or can race and break valid lock.
   306         try:
   309         try:
   307             l = lock(self.vfs, self.f + '.break', timeout=0)
   310             l = lock(self.vfs, self.f + '.break', timeout=0)