try/finally question

Erno Kuusela erno-news at erno.iki.fi
Wed Jul 10 09:33:42 EDT 2002


In article <7xd6twow3x.fsf_-_ at ruckus.brouhaha.com>, Paul Rubin
<phr-n2002b at NOSPAMnightsong.com> writes:

| So the obvious way to use it is:

|    try:
|       db.begin()
|       x = db.do_action(first_thing)
|       y = db.do_action(second_thing)
|       db.commit()
|    finally:
|       db.cancel()

| The trouble is db.cancel() is an ordinary method call--it's not atomic
| in the interpreter.  It can be interrupted and blast out of the
| finally block before finishing, and then control returns to some
| higher level with the database still locked.

would it be different from the an interrupt coming
at any point between the begin and the commit?

if you want to do database transactions in the
signal handler, you will probably get an error if you try to
begin() before closing the previous transaction, but that same
problem would be in the try block too.

if you never call neither commit or cancel but just exit, the effect
in all the systems i have seen is effectively the same as calling
cancel.

  -- erno







More information about the Python-list mailing list