Re: Extensible compound statements -- new exec flavor

Hannu Krosing (hannu@estib.ee)
24 Jan 1995 19:18:57 GMT

jfulton@dsjfqvarsa.er.usgs.GOV (Jim Fulton ) wrote:
>
>
> I am looking at the use of nested transactions for distributed object
> programming in Python. (This is based on the models given in "Atomic
> Transactions", by Lynch, Merrit, Weihl, and Fekete.) In implementing
> nested transactions in python, I find that I would like to be able to
> use a syntax like:
>
> transaction:
> # some code
> # that makes up the transaction
> transaction:
> # This is a sub transaction
> # Perhaps more code for the first transaction
>
> the idea being that transactions hava associated blocks of code. If a
> block executes completely, then the associated transaction commits.
> If an exception is raised, then the the transaction aborts and
> propigates the exception. If a transaction, aborts on its own, it
> raises an abort exception.
>
> It appears that without something like the above capability,
> implementing nested transactions is surprizingly ugly. This is due to
> the fact that I need to closely tie the initiation and completion of a
> transaction. Without an automated (i.e. language-supported)
> mechansism, I have to resort to either inelegent or unreliable
> mechanisms involving explicit user-supplied transaction commits.
> These user-supplied commits will have to name the corresponding
> transaction, requiring the management of additional variables to hold
> the transaction information.

As i see no meaning for interleaved transactions i can see no use of
using t1 and t2 (except to ensure destruction and thus rollback of
transactions when they go out of scope (or some time later))

Is'nt the same easily written like this using a Transaction object
with methods for keeping a stack of nested transactions

from transaction import *

Transaction = transaction(ThingThisTransactsOn)

try:
Transaction.Begin()
# some outer transaction code
try:
Transaction.Begin()
# do the sub-transaction stuff here
Transaction.Commit()
except (AnyButBeginOrCommitError):
Transaction.Rollback()
# some other cleanup
# some more outer transaction code
Transaction.Commit()
except (AnyButBeginOrCommitError):
Transaction.Rollback()
# some cleanup for failed outer transaction
# some non-transactional code (is there actually any? :)

aren't transactions just one kind of exception handling anyway?
perhaps we can make it into:

try(Transaction): # implies Transaction.Begin(), and
# Transaction.Commit() on success/no exception
#some transaction code
try(Transaction):
# do the sub-transaction stuff here
except (Any): # implies Transaction.Rollback() for inner trx
# some other cleanup
# some more outer transaction code
except ():
# some extra cleanup for failed outer transaction
# some non-transactional code (is there actually any? :)

Disclaimer: I am quite new to python,so i may be talking nonsense.

------------------------------
Hannu Krosing / hannu@estib.ee