[Zope-dev] Transaction environment in threaded zope-product
Dieter Maurer
dieter@handshake.de
Fri, 9 Nov 2001 22:03:36 +0100
Christian Theune writes:
> I have a zope product, that uses threads, to control programs
> running outside zope and doing some async stuff.
>
> What I found is, that i can't do changes from the self-started
> thread (ChrisW: that's the problem... ;) ).
>
> But how do I get into a transaction do be able to change things on
> persistent objects?
You need a ZODB connection in order to be able to change objects
in the ZODB.
You get one (in your new thread!) by
from Zope import app
root= app() # the ZODB root object but without 'RequestContainer'
You can now build a new REQUEST object and use "BaseRequest.traverse"
to reach the object you want (identified by an URL).
Before you change anything, you need to begin a transaction
and finally either commit or abort it.
Dieter