bzrlib should provide context managers for locking

Bug #522195 reported by Henning Eggers
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Wishlist
Unassigned

Bug Description

In a recent Launchpad branch I implemented this:

class ReadLockTree(object):
    """Context manager to claim a read lock on a bzr tree."""

    def __init__(self, tree):
        self.tree = tree

    def __enter__(self):
        self.tree.lock_read()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.tree.unlock()
        return False

And used it like this:

  with ReadLockTree(tree):
      tree.do_something_even_trow_exception_or_return

It would be great if it was generally integrated into bzrlib so that it can be used like this:

  with lockable_object.read_lock():
      lockable_object.do_something_even_trow_exception_or_return

Same for write locks.

Related branches

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 522195] [NEW] bzrlib should provide context managers for locking

 importance wishlist
 status confirmed
 done

Thanks; if you'd like this integrated, I suggest writing some tests for
it (python 2.4 compatible!) and proposing a merge.

It could live in the decorators module or the cleanup module, or even a
new one.

-Rob

Changed in bzr:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Martin Pool (mbp) wrote :

Thanks for working on this, Henning. Please propose a merge when you're ready and just ask if you want help.

Changed in bzr:
status: Confirmed → In Progress
tags: added: locking
Jelmer Vernooij (jelmer)
Changed in bzr:
status: In Progress → Confirmed
Jelmer Vernooij (jelmer)
tags: added: check-for-breezy
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.