[Zope-dev] Python objects and transactions
Michel Pelletier
michel@digicool.com
Mon, 21 Feb 2000 17:07:44 -0800
Duncan Booth wrote:
>
> Is there an easy way for a python object to know when a web
> request has completed?
There is a subtle difference between when a web request 'ends' and when
a transaction gets commited. They usualy occour relativly
simultaneously to the user, but underneath they are two different
operations.
> For example, if I have an object that needs to do some setup and
> tidy up around operations, I want to group operations together if
> possible, but I don't want to delay the tidy up until the object is
> thrown out of the cache.
I think perhaps you are looking for __bobo_before__ and __bobo_after__.
If your object defines these two methods then the first will be called
before the object is called by ZPublisher, and the second will be called
after (ZPublisher used to be called Bobo).
> I have tried using the mixin class Shared.DC.ZRDB.TM and defining
> _abort, _finish, but without much success. The first time I call
> _register the _finish method is called as I expected, but the
> transaction forces a commit, which writes the object to the ZODB
> with _registered set to 1 so that subsequent attempts to start a
> transaction fail. Besides, this forces a transaction on the ZODB
> which I would really rather avoid.
Yeah, I wouldn't mess too much with the transactions...
-Michel