Re: what does transaction.abort() refresh?
Jim Fulton <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <CAPDm-FgbhNvic6Yc_0QR37KCQMSsCGcb5k3f4P0YfyniqL+kxg@mail.gmail.com> |
On Wed, Oct 5, 2016 at 5:49 PM, Boylan, Ross <[email protected]> wrote: > How do I know if I have the threaded transaction manager? If you use the begin, abort, or commit functions in the transaction manager, you're using the thread-local ("threaded" was a brain fart, sorry) transaction manager. Similarly, if you create a connection by calling open on a database without arguments, then the connection is using a thread-local transaction manager. You are doing those things below, so both the connection and the code are using the same transaction manager. > I just did import transaction. > The other thread does NOT reassign conn.root.x; it gets x, modifies it, and commits. > > BTW, I'm only using threads as a warmup; eventually it will be zeo from different processes (probably). > > Here's the business end of the code that worked. The version that didn't work used the commented out > aVariant.add(aRun) instead of the retrieval through the root object. > > #! /usr/bin/python3 > import pdb > from persistent import Persistent > from datetime import datetime > from BTrees.IOBTree import IOBTree > import sys, threading, time, transaction, ZODB > > # class definitions omitted; all are subclasses of Persistent > ___def tickle(i, me, you): > start = datetime.now() > conn = db.open() > if i==1: > aManager = Manager() > conn.root.manager = aManager > aVariant = Variant(1) > aManager.addVariant(aVariant) > transaction.commit() > print("added variant") > you.release() > me.acquire() > else: > me.acquire() > aManager = conn.root.manager > aVariant = aManager._variants[1] > transaction.abort() > aRun = OneRun(i, start, datetime.now(), 0) > # not aVariant.add(aRun) > conn.root.manager._variants[1].add(aRun) > print(i) > transaction.commit() > you.release() > me.acquire() > transaction.abort() > aRun = OneRun(i+2, start, datetime.now(), 0) > print(i+2) > # not aVariant.add(aRun) > conn.root.manager._variants[1].add(aRun) > transaction.commit() > you.release() > me.acquire() > transaction.abort() > if i==1: > conn.root.manager.dump(sys.stdout) > conn.close() > you.release() > > db= ZODB.DB(dbname) > l1 = threading.Lock() > l2 = threading.Lock() > l1.acquire() > l2.acquire() > t1 = threading.Thread(target=tickle, args=(1, l1, l2)) > t2 = threading.Thread(target=tickle, args=(2, l2, l1)) > t1.start() > t2.start() > t1.join() > t2.join() > db.close() This code is rather complicated and leaves out a lot of details. I could ask questions, but that would lead to more questions and probably not a good use of time. :) The short answer is that your gemstone mental model is correct. If you're getting different behavior, it's likely due to an issue with your code. Jim -- Jim Fulton http://jimfulton.info -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.