~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Locking using OS file locks or file existence.
18
19
 
19
20
Note: This method of locking is generally deprecated in favour of LockDir, but
33
34
unlock() method.
34
35
"""
35
36
 
36
 
from __future__ import absolute_import
37
 
 
38
 
import contextlib
39
37
import errno
40
38
import os
41
39
import sys
48
46
    trace,
49
47
    )
50
48
from bzrlib.hooks import Hooks
51
 
from bzrlib.i18n import gettext
 
49
 
52
50
 
53
51
class LockHooks(Hooks):
54
52
 
173
171
            self.f.close()
174
172
            self.f = None
175
173
 
 
174
    def __del__(self):
 
175
        if self.f:
 
176
            from warnings import warn
 
177
            warn("lock on %r not released" % self.f)
 
178
            self.unlock()
 
179
 
176
180
    def unlock(self):
177
181
        raise NotImplementedError()
178
182
 
537
541
    locked the same way), and -Drelock is set, then this will trace.note a
538
542
    message about it.
539
543
    """
540
 
 
 
544
    
541
545
    _prev_lock = None
542
546
 
543
547
    def _note_lock(self, lock_type):
546
550
                type_name = 'read'
547
551
            else:
548
552
                type_name = 'write'
549
 
            trace.note(gettext('{0!r} was {1} locked again'), self, type_name)
 
553
            trace.note('%r was %s locked again', self, type_name)
550
554
        self._prev_lock = lock_type
551
555
 
552
 
@contextlib.contextmanager
553
 
def write_locked(lockable):
554
 
    lockable.lock_write()
555
 
    try:
556
 
        yield lockable
557
 
    finally:
558
 
        lockable.unlock()