RE: what does transaction.abort() refresh?

"Boylan, Ross" <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>
OK, I RTFM http://www.zodb.org/en/latest/guide/transactions-and-threading.html#explicit-transaction-managers and see I'm definitely not doing that.  Will try it.
Ross
________________________________________
From: [email protected] [[email protected]] on behalf of Boylan, Ross [[email protected]]
Sent: Wednesday, October 05, 2016 2:49 PM
To: Jim Fulton
Cc: zodb ‎[[email protected]]‎
Subject: RE: [ZODB] what does transaction.abort() refresh?

How do I know if I have the threaded 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()

Ross
_____________________________________
From: [email protected] [[email protected]] on behalf of Jim Fulton [[email protected]]
Sent: Wednesday, October 05, 2016 1:42 PM
To: Boylan, Ross
Cc: zodb ‎[[email protected]]‎
Subject: Re: [ZODB] what does transaction.abort() refresh?

On Wed, Oct 5, 2016 at 4:21 PM, Boylan, Ross <[email protected]> wrote:
> My mental model, perhaps from Gemstone,

Gemstone!

> is that if I do
> x1 = conn.root.x
> # stuff
> # another thread changes what's in root.x
> transaction.abort()
> that x1 will now have the value of root.x from the other thread.

Yes, assuming conn was using the threaded transaction manager, x1 is a
persistent object and the other thread mutated it.

> But when I do this, x1 seems to be unchanged; I have to go back through conn.root.x to get the new version of the object.

Is conn.root.x a persistent object?

Does the other thread reassign conn.root.x?

Jim

>
> Is my revised understanding correct?
>
> Using ZODB 5, python 3.4.
>
> Thanks.
> Ross Boylan
>
> --
> 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.



--
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.

-- 
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.