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

Ariel Argañaraz arielin82 at gmail.com
Tue Apr 29 17:05:24 EDT 2014


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.

-- 
Ariel Argañaraz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140429/aaa8b045/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.py
Type: application/x-download
Size: 2115 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140429/aaa8b045/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: objects.py
Type: application/x-download
Size: 1853 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140429/aaa8b045/attachment-0001.bin>


More information about the Python-list mailing list