[Zope-dev] kudos...

Chris McDonough chrism at plope.com
Mon Aug 8 16:44:35 EDT 2011


Kudos to whomever turned the "transaction" package's transaction manager
into a context manager and was thoughtful enough to provide the
"attempts" method (which returns a separate context manager, wrapping
the txn context manager, and retries some number of configurable times).
This makes writing code that integrates with a web system that commits
or aborts as easy as:

         import transaction

         for attempt in transaction.attempts(attempts):
            with attempt as t:
                response = handler(request)

                if t.isDoomed():
                    t.abort()

                if commit_veto is not None:
                    veto = commit_veto(request, response)
                    veto and t.abort()

                return response

Very nice.

- C




More information about the Zope-Dev mailing list