Re: [Zope-dev] Transaction environment in threaded zope-product
You should be able to pass the database into a thread object and obtain a connection from it in order to manipulate the underlying database like so: class YourThread(threading.Thread): def __init__(self, db): self.db = db def run(self): threading.Thread.run(self) self.doSomething() def doSomething(self): conn = self.db.open() root = conn.root() app = root['Application'] print app.Control_Panel.objectIds() app.foo = 'bar' get_transaction().commit() Then in your code that has a reference to the database via persistence: db = self._p_jar._db worker = YourThread(db) worker.start() - Original Message - From: Christian Theune [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, November 09, 2001 6:46 AM Subject: [Zope-dev] Transaction environment in threaded zope-product Hi. 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? get_transaction().begin() doesn't work, and I don't find any documentation to get started from ... plz help me Christian -- Christian Theune - [EMAIL PROTECTED] gocept gmbh co.kg - schalaunische strasse 6 - 06366 koethen/anhalt tel.+49 3496 3099112 - fax.+49 3496 3099118 mob. - 0178 48 33 981 reduce(lambda x,y:x+y,[chr(ord(x)^42) for x in 'zS^BED\nX_FOY\x0b']) ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope ) ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] Transaction environment in threaded zope-product
Hi. 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? get_transaction().begin() doesn't work, and I don't find any documentation to get started from ... plz help me Christian -- Christian Theune - [EMAIL PROTECTED] gocept gmbh co.kg - schalaunische strasse 6 - 06366 koethen/anhalt tel.+49 3496 3099112 - fax.+49 3496 3099118 mob. - 0178 48 33 981 reduce(lambda x,y:x+y,[chr(ord(x)^42) for x in 'zS^BED\nX_FOY\x0b']) ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Transaction environment in threaded zope-product
Christian Theune wrote: I have a zope product, that uses threads, to control programs running outside zope and doing some async stuff. You do realise that's pointing a loaded gun at your own head? get_transaction().begin() doesn't work, and I don't find any documentation to get started from ... Maybe you're looking for get_transaction().commit()? But, to be able to see the results in another thread, that thread would probabyl need to do get_transaction().begin(). Just so you're aware, I think you're wandering through a minefield with this one... Chris ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Transaction environment in threaded zope-product
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 ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )