ZODB problem to change an attribute from 2 diferent threads

19 views
Skip to first unread message

Ariel Argañaraz

unread,
Apr 23, 2014, 6:11:57 PM4/23/14
to pylons-...@googlegroups.com
Hi, I have a problem with threads.

The documentation says:
A process
with multiple threads will often have multiple connections to the same database, with different threads having different connections.

But I don't Know if I create different connections in the right way.

I have 2 threads.

In the main.py, the connection works well with this:
#main.py

db = ZODB.config.databaseFromURL('configs/database.conf')
connection = db.open()
root = connection.root()

I have a function that change something in the object I want to persist. When I use this function locally all works perfect, The element is updated and saved.
def changePos(self, x):
     """a function to change the x position of an element"""
     self.element._x = x
     self._p_changed = True
     transaction.commit()
     print "change success"

The second thread is launched from the main.py. It is a xml-rpc server. That serves the mentioned method "changePos()"
i create the connection in that thread like this.
db2 = ZODB.config.databaseFromURL('configs/database.conf')
connection2 = db2.open()
root2 = connection2.root()

But the problem is that, when I call "changePos(3)" with a xml-rpc client. It seems to do the job because it changes the X value and print the "change success" message but when I stop the main.py and inspect the X value from the data.fs with the Eye program or with another python script to show the X value I can see that the X value is not "3" as I would expect. So the change was not commited!

Can someone give some help with this? maybe i am doing something wrong, or if anyone has an example of how to deal with threads, i 'd be very gratefull.

BTW: I try to use the ZEO and I made and example with 2 diferent process and it works but I can't do it with 2 threads!

Chris McDonough

unread,
Apr 23, 2014, 6:17:12 PM4/23/14
to pylons-...@googlegroups.com
On 04/23/2014 06:11 PM, Ariel Argañaraz wrote:
> Hi, I have a problem with threads.

You'll want to ask this question at
<https://groups.google.com/forum/#!forum/zodb>. The Pylons Project does
not maintain ZODB.

>
> The documentation says:
> A processwith multiple threads will often have multiple connections to
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pylons-discus...@googlegroups.com
> <mailto:pylons-discus...@googlegroups.com>.
> To post to this group, send email to pylons-...@googlegroups.com
> <mailto:pylons-...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Ariel Argañaraz

unread,
Apr 23, 2014, 6:25:44 PM4/23/14
to pylons-...@googlegroups.com
Ok, Sorry.

I asked in the zodb as well, I found some people asking  about zodb here so I did it. Sorry again
Reply all
Reply to author
Forward
0 new messages