[Zope-dev] Transaction environment in threaded zope-product

Chris McDonough chrism@zope.com
Mon, 26 Nov 2001 16:44:45 -0500


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" <ct@gocept.com>
To: <zope-dev@zope.org>
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 - ct@gocept.com
> 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  -  Zope-Dev@zope.org
> 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 )
>