~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-23 23:21:12 UTC
  • mfrom: (1953 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: john@arbash-meinel.com-20060823232112-f755378d583374a8
[merge] bzr.dev 1953

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
import os
98
98
import time
99
 
from cStringIO import StringIO
 
99
from StringIO import StringIO
100
100
 
101
101
import bzrlib.config
102
102
from bzrlib.errors import (
111
111
        ResourceBusy,
112
112
        UnlockableTransport,
113
113
        )
114
 
from bzrlib.trace import mutter, note
 
114
from bzrlib.trace import mutter
115
115
from bzrlib.transport import Transport
116
116
from bzrlib.osutils import rand_chars
117
117
from bzrlib.rio import RioWriter, read_stanza, Stanza
130
130
# TODO: Make sure to pass the right file and directory mode bits to all
131
131
# files/dirs created.
132
132
 
133
 
_DEFAULT_TIMEOUT_SECONDS = 60
 
133
_DEFAULT_TIMEOUT_SECONDS = 300
134
134
_DEFAULT_POLL_SECONDS = 0.5
135
135
 
136
136
class LockDir(object):
160
160
        self._dir_modebits = dir_modebits
161
161
        self.nonce = rand_chars(20)
162
162
 
163
 
        self._report_function = note
164
 
 
165
163
    def __repr__(self):
166
164
        return '%s(%s%s)' % (self.__class__.__name__,
167
165
                             self.transport.base,
357
355
        # XXX: the transport interface doesn't let us guard 
358
356
        # against operations there taking a long time.
359
357
        deadline = time.time() + timeout
360
 
        commented = False
361
358
        while True:
362
359
            try:
363
360
                self.attempt_lock()
364
361
                return
365
362
            except LockContention:
366
363
                pass
367
 
            if not commented:
368
 
                commented = True
369
 
                self._report_function('Unable to obtain lock on %s\n'
370
 
                                      'Will continue to try for %s seconds\n',
371
 
                                      self.transport.abspath(self.path),
372
 
                                      timeout)
373
 
 
374
364
            if time.time() + poll < deadline:
375
365
                time.sleep(poll)
376
366
            else:
378
368
 
379
369
    def lock_write(self):
380
370
        """Wait for and acquire the lock."""
381
 
        self.wait_lock()
 
371
        self.attempt_lock()
382
372
 
383
373
    def lock_read(self):
384
374
        """Compatibility-mode shared lock.