# HG changeset patch # User Bryan O'Sullivan # Date 2007-07-19 22:13:48 # Node ID 3e25a6eb5c9aab6742fe73ebbfaddf9244f520e3 # Parent e8f4e40f285a9724882956e7d80dbf728cea7047 lock.py: cache hostname, but not pid, in case we fork diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -29,14 +29,13 @@ class lock(object): # 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 @@ class lock(object): 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 @@ class lock(object): host, pid = locker.split(":", 1) except ValueError: return locker - if host != self.host: + if host != lock._host: return locker try: pid = int(pid)