~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/decorators.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-31 01:54:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3497.
  • Revision ID: andrew.bennetts@canonical.com-20080331015438-1k5c8mqeag6ff9vk
Try not to lose the original exception in needs_write_lock decorator if the unlock raises a secondary exception.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
           ]
23
23
 
24
24
 
 
25
import sys
 
26
 
 
27
 
25
28
def _get_parameters(func):
26
29
    """Recreate the parameters for a function using introspection.
27
30
 
138
141
def %(name)s_write_locked(%(params)s):
139
142
    self.lock_write()
140
143
    try:
141
 
        return unbound(%(passed_params)s)
142
 
    finally:
 
144
        result = unbound(self, *args, **kwargs)
 
145
    except:
 
146
        exc_info = sys.exc_info()
 
147
        try:
 
148
            self.unlock()
 
149
        finally:
 
150
            raise exc_info[0], exc_info[1], exc_info[2]
 
151
    else:
143
152
        self.unlock()
 
153
        return result
144
154
write_locked = %(name)s_write_locked
145
155
"""
146
156
    params, passed_params = _get_parameters(unbound)
162
172
    def write_locked(self, *args, **kwargs):
163
173
        self.lock_write()
164
174
        try:
165
 
            return unbound(self, *args, **kwargs)
166
 
        finally:
 
175
            result = unbound(self, *args, **kwargs)
 
176
        except:
 
177
            exc_info = sys.exc_info()
 
178
            try:
 
179
                self.unlock()
 
180
            finally:
 
181
                raise exc_info[0], exc_info[1], exc_info[2]
 
182
        else:
167
183
            self.unlock()
 
184
            return result
168
185
    write_locked.__doc__ = unbound.__doc__
169
186
    write_locked.__name__ = unbound.__name__
170
187
    return write_locked