~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/lockfile.py

  • Committer: Michael Hudson
  • Date: 2008-06-22 23:53:25 UTC
  • Revision ID: michael.hudson@canonical.com-20080622235325-fs0yapvfxn3xhkro
make serve-branches.py executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    lock may be acquired multiple times by the same thread, as long as it's
36
36
    released an equal number of times.  unlike threading.Lock, this lock can
37
37
    be used across processes.
38
 
    
 
38
 
39
39
    this uses os.open(O_CREAT|O_EXCL), which apparently works even on windows,
40
40
    but will not work over NFS, if anyone still uses that.  so don't put the
41
41
    cache folder on an NFS server...
50
50
            # remove stale locks left over from a previous run
51
51
            if time.time() - os.stat(filename).st_mtime > MAX_STALE_TIME:
52
52
                os.remove(filename)
53
 
    
 
53
 
54
54
    @with_lock
55
55
    def _try_acquire(self):
56
56
        if self._count > 0:
63
63
            return True
64
64
        except OSError:
65
65
            return False
66
 
    
 
66
 
67
67
    def acquire(self):
68
68
        # try over and over, sleeping on exponential backoff with an upper limit of about 5 seconds
69
69
        pause = 0.1