comparison mercurial/lock.py @ 30920:dc9f086c7691

lock: move lock._host calculation to a function This allows customization per platform. See the next patch for why.
author Jun Wu <quark@fb.com>
date Fri, 10 Feb 2017 13:35:21 -0800
parents 518c3e392f75
children 1f151a33af8e
comparison
equal deleted inserted replaced
30919:e1fa5fe9f9d4 30920:dc9f086c7691
15 15
16 from . import ( 16 from . import (
17 error, 17 error,
18 util, 18 util,
19 ) 19 )
20
21 def _getlockprefix():
22 """Return a string which is used to differentiate pid namespaces
23
24 It's useful to detect "dead" processes and remove stale locks with
25 confidence. Typically it's just hostname.
26 """
27 return socket.gethostname()
20 28
21 class lock(object): 29 class lock(object):
22 '''An advisory lock held by one process to control access to a set 30 '''An advisory lock held by one process to control access to a set
23 of files. Non-cooperating processes or incorrectly written scripts 31 of files. Non-cooperating processes or incorrectly written scripts
24 can ignore Mercurial's locking scheme and stomp all over the 32 can ignore Mercurial's locking scheme and stomp all over the
97 def _trylock(self): 105 def _trylock(self):
98 if self.held: 106 if self.held:
99 self.held += 1 107 self.held += 1
100 return 108 return
101 if lock._host is None: 109 if lock._host is None:
102 lock._host = socket.gethostname() 110 lock._host = _getlockprefix()
103 lockname = '%s:%s' % (lock._host, self.pid) 111 lockname = '%s:%s' % (lock._host, self.pid)
104 retry = 5 112 retry = 5
105 while not self.held and retry: 113 while not self.held and retry:
106 retry -= 1 114 retry -= 1
107 try: 115 try: