Mercurial > public > mercurial-scm > hg-stable
diff mercurial/lock.py @ 35219:9153871d50e0
lock: allow to configure when the lock messages are displayed
We add a new 'ui.timeout.warn' config to set a grace period before we display
lock related warning:
waiting for lock on PATH held by PROCESS
The config is based on 'ui.timeout' and expresses a number of seconds before
the warning is displayed. Negative values disable the warning altogether.
The messages go to the debug output to help people trouble-shooting deadlocks.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Wed, 29 Nov 2017 20:39:59 -0500 |
parents | 1b758105b5c7 |
children | 4b1c04082cdc |
line wrap: on
line diff
--- a/mercurial/lock.py Wed Nov 29 20:36:29 2017 -0500 +++ b/mercurial/lock.py Wed Nov 29 20:39:59 2017 -0500 @@ -41,11 +41,11 @@ raise return result -def trylock(ui, vfs, lockname, timeout, *args, **kwargs): +def trylock(ui, vfs, lockname, timeout, warntimeout, *args, **kwargs): """return an acquired lock or raise an a LockHeld exception - This function is responsible to issue warnings about the held lock while - trying to acquires it.""" + This function is responsible to issue warnings and or debug messages about + the held lock while trying to acquires it.""" def printwarning(printer, locker): """issue the usual "waiting on lock" message through any channel""" @@ -60,9 +60,12 @@ l = lock(vfs, lockname, 0, *args, dolock=False, **kwargs) + debugidx = 0 if (warntimeout and timeout) else -1 warningidx = 0 if not timeout: warningidx = -1 + elif warntimeout: + warningidx = warntimeout delay = 0 while True: @@ -70,6 +73,8 @@ l._trylock() break except error.LockHeld as inst: + if delay == debugidx: + printwarning(ui.debug, inst.locker) if delay == warningidx: printwarning(ui.warn, inst.locker) if timeout <= delay: @@ -80,7 +85,10 @@ l.delay = delay if l.delay: - ui.warn(_("got lock after %s seconds\n") % l.delay) + if 0 <= warningidx <= l.delay: + ui.warn(_("got lock after %s seconds\n") % l.delay) + else: + ui.debug("got lock after %s seconds\n" % l.delay) if l.acquirefn: l.acquirefn() return l