##// END OF EJS Templates
add a timeout when a lock is held (default 1024 sec)...
Benoit Boissinot -
r1787:e431344e default
parent child Browse files
Show More
@@ -247,6 +247,9 b' ui::'
247 remote command to use for clone/push/pull operations. Default is 'hg'.
247 remote command to use for clone/push/pull operations. Default is 'hg'.
248 ssh;;
248 ssh;;
249 command to use for SSH connections. Default is 'ssh'.
249 command to use for SSH connections. Default is 'ssh'.
250 timeout;;
251 The timeout used when a lock is held (in seconds), a negative value
252 means no timeout. Default is 1024.
250 username;;
253 username;;
251 The committer of a changeset created when running "commit".
254 The committer of a changeset created when running "commit".
252 Typically a person's name and email address, e.g. "Fred Widget
255 Typically a person's name and email address, e.g. "Fred Widget
@@ -261,7 +261,14 b' class localrepository(object):'
261 if not wait:
261 if not wait:
262 raise inst
262 raise inst
263 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0])
263 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0])
264 l = lock.lock(self.join(lockname), wait, releasefn)
264 try:
265 # default to 1024 seconds timeout
266 l = lock.lock(self.join(lockname),
267 int(self.ui.config("ui", "timeout") or 1024),
268 releasefn)
269 except lock.LockHeld, inst:
270 raise util.Abort(_("timeout while waiting for "
271 "lock held by %s") % inst.args[0])
265 if acquirefn:
272 if acquirefn:
266 acquirefn()
273 acquirefn()
267 return l
274 return l
@@ -16,10 +16,10 b' class LockUnavailable(LockException):'
16 pass
16 pass
17
17
18 class lock(object):
18 class lock(object):
19 def __init__(self, file, wait=1, releasefn=None):
19 def __init__(self, file, timeout=-1, releasefn=None):
20 self.f = file
20 self.f = file
21 self.held = 0
21 self.held = 0
22 self.wait = wait
22 self.timeout = timeout
23 self.releasefn = releasefn
23 self.releasefn = releasefn
24 self.lock()
24 self.lock()
25
25
@@ -27,13 +27,16 b' class lock(object):'
27 self.release()
27 self.release()
28
28
29 def lock(self):
29 def lock(self):
30 timeout = self.timeout
30 while 1:
31 while 1:
31 try:
32 try:
32 self.trylock()
33 self.trylock()
33 return 1
34 return 1
34 except LockHeld, inst:
35 except LockHeld, inst:
35 if self.wait:
36 if timeout != 0:
36 time.sleep(1)
37 time.sleep(1)
38 if timeout > 0:
39 timeout -= 1
37 continue
40 continue
38 raise inst
41 raise inst
39
42
General Comments 0
You need to be logged in to leave comments. Login now