Problems with ZODB,I can not persist and object accessed from 2 threads

A

Ariel Argañaraz

Hello, I am sorry I am stuck in this. And I need some help

I want to persist an Object with ZODB, the object can be accessed from 2
different threads. The ZODB manual says:

A multi-threaded program should open a separate Connection instance for
each thread. Different threads can then modify objects and commit their
modifications independently.

But there isn't an example of how to create a connection for each thread.
Can someone tell me how to connect to the same DB from 2 threads??

I attached an example of what I am trying to do.

And I get this error.

Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "main.py", line 33, in thread_1
storage = FileStorage("/tmp/asdasd.fs")
File "/usr/lib/python2.7/site-packages/ZODB/FileStorage/FileStorage.py",
line 164, in *_init_*
self._lock_file = LockFile(file_name + '.lock')
File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 84,
in *_init_*
_lock_file(fp)
File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 59,
in _lock_file
raise LockError("Couldn't lock %r" % file.name)
LockError: Couldn't lock '/tmp/asdasd.fs.lock'


IF I don't connect in the "thread_1" class I can change things but
sometimes the changes from the main thread are not commited.

When I debug, I can see that when a change is made from the Second thread,
the "transaction_manager" creates a new Transaction here:

#manager.py
def get(self):
""" See ITransactionManager.
"""
if self._txn is None:
self._txn = Transaction(self._synchs, self)
return self._txn

When it happens that commit Seems to be executed succesfully but it doest
save the changes to the DB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top