Question about transaction usage
Matt Mackall
mpm at selenic.com
Sat Oct 3 21:36:55 UTC 2009
On Sat, 2009-10-03 at 17:22 -0400, Greg Ward wrote:
> Michael Haggerty has been reviewing my patches to add a Mercurial
> backend to cvs2svn, and asked me about a peculiar-looking method:
>
> def _commit_memctx(self, mctx):
> txn = self.repo.transaction()
> try:
> node = self.repo.commitctx(mctx)
> txn.close()
> finally:
> del txn
> return node
>
> In particular, he observed that the "finally" block is completely
> useless: all it does is decrement the ref count on txn, which is about
> to go out of scope anyways. So why bother?
Unfortunately, destructors in Python are basically useless. If an
exception is thrown, the traceback object will hold references to every
stack frame in the call chain, preventing the destructors from getting
invoked in a timely fashion (and sometimes at all!).
So we make a point of manually destroying locks and transactions.
--
http://selenic.com : development and support for Mercurial and Linux
More information about the Mercurial-devel
mailing list