Mercurial > hg-stable
changeset 4947:3e25a6eb5c9a
lock.py: cache hostname, but not pid, in case we fork
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 19 Jul 2007 15:13:48 -0700 |
parents | e8f4e40f285a |
children | c8d1aa1822d5 |
files | mercurial/lock.py |
diffstat | 1 files changed, 7 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/lock.py Thu Jul 19 12:41:07 2007 -0700 +++ b/mercurial/lock.py Thu Jul 19 15:13:48 2007 -0700 @@ -29,14 +29,13 @@ # old-style lock: symlink to pid # new-style lock: symlink to hostname:pid + _host = None + def __init__(self, file, timeout=-1, releasefn=None, desc=None): self.f = file self.held = 0 self.timeout = timeout self.releasefn = releasefn - self.id = None - self.host = None - self.pid = None self.desc = desc self.lock() @@ -59,13 +58,12 @@ inst.locker) def trylock(self): - if self.id is None: - self.host = socket.gethostname() - self.pid = os.getpid() - self.id = '%s:%s' % (self.host, self.pid) + if lock._host is None: + lock._host = socket.gethostname() + lockname = lock._host + ':' + str(os.getpid()) while not self.held: try: - util.makelock(self.id, self.f) + util.makelock(lockname, self.f) self.held = 1 except (OSError, IOError), why: if why.errno == errno.EEXIST: @@ -93,7 +91,7 @@ host, pid = locker.split(":", 1) except ValueError: return locker - if host != self.host: + if host != lock._host: return locker try: pid = int(pid)