<div dir="ltr"><span dir="ltr">Hello, I am sorry I am stuck in this. And I need some help<br><br>I want to persist an Object with ZODB, the object can be accessed from 2 different threads. The ZODB manual says:<br><br>A multi-threaded program should open a
separate Connection instance for each thread. Different threads can then
modify objects and commit their modifications independently.<br><br>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??<br><br>I attached an example of what I am trying to do.<br><br>And I get this error.<br></span><br><span dir="ltr"><span dir="ltr">Traceback (most recent call last):<br>
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner<br> self.run()<br> File "/usr/lib/python2.7/threading.py", line 763, in run<br> self.__target(*self.__args, **self.__kwargs)<br>
File "main.py", line 33, in thread_1<br> storage = FileStorage("/tmp/asdasd.fs")<br> File "/usr/lib/python2.7/site-packages/ZODB/FileStorage/FileStorage.py", line 164, in <i>_init_</i><br>
self._lock_file = LockFile(file_name + '.lock')<br> File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 84, in <i>_init_</i><br> _lock_file(fp)<br> File "/usr/lib/python2.7/site-packages/zc/lockfile/__init__.py", line 59, in _lock_file<br>
raise LockError("Couldn't lock %r" % <a href="http://file.name" target="_blank">file.name</a>)<br>LockError: Couldn't lock '/tmp/asdasd.fs.lock'</span><br><br><br>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.<br>
<br>When
I debug, I can see that when a change is made from the Second thread,
the "transaction_manager" creates a new Transaction here:<br><br>#manager.py<br> def get(self):<br> """ See ITransactionManager.<br> """<br> if self._txn is None:<br>
self._txn = Transaction(self._synchs, self)<br> return self._txn<br><br>When it happens that commit Seems to be executed succesfully but it doest save the changes to the DB.</span><br clear="all"><br>-- <br>
Ariel Argaņaraz<br><br><br>
</div>