Zc.lockfile.LockError in ZODB

I am trying to use ZODB 3.10.2 on my web server running Debian and Python 2.7.1. It seems that every time I try to access one database from two different processes, I get a cryptic exception. I tried to access the database from an interactive Python session, and everything seemed to work just fine:

>>> import ZODB >>> from ZODB.FileStorage import FileStorage >>> storage = FileStorage("test.db") >>> 

But then I tried the same sequence of commands from another session running at the same time, and this did not seem to me useful:

 >>> import ZODB >>> from ZODB.FileStorage import FileStorage >>> storage = FileStorage("test.db") No handlers could be found for logger "zc.lockfile" Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/ZODB3-3.10.2-py2.7-linux-x86_64.egg/ZODB/FileStorage/FileStorage.py", line 125, in __init__ self._lock_file = LockFile(file_name + '.lock') File "/usr/local/lib/python2.7/site-packages/zc.lockfile-1.0.0-py2.7.egg/zc/lockfile/__init__.py", line 76, in __init__ _lock_file(fp) File "/usr/local/lib/python2.7/site-packages/zc.lockfile-1.0.0-py2.7.egg/zc/lockfile/__init__.py", line 59, in _lock_file raise LockError("Couldn't lock %r" % file.name) zc.lockfile.LockError: Couldn't lock 'test.db.lock' >>> 

Why is this happening? What can be done about this?

+4
source share
2 answers

ZODB does not support multiprocessor access. This is why you get a blocking error; ZODB file storage was blocked by one process so that other processes did not modify it.

There are several ways. The easiest option is to use ZEO . ZEO extends ZODB equipment to provide access to objects over the network, and you can easily configure ZODB to access the ZEO server instead of the local FileStorage file:

 <zodb> <zeoclient> server localhost:9100 </zeoclient> </zodb> 

Another option is to use RelStorage , which stores ZODB data in a relational database. RelStorage supports PostgreSQL, Oracle, and MySQL servers. RelStorage takes care of concurrent access from different ZODB clients. Here is an example configuration:

 <zodb> <relstorage> <postgresql> # The dsn is optional, as are each of the parameters in the dsn. dsn dbname='zodb' user='username' host='localhost' password='pass' </postgresql> </relstorage> </zodb> 

RelStorage requires more pre-configuration, but can outperform ZEO in many scenarios.

+11
source

You cannot access the same database files from two processes at the same time (which is obvious). That is why you get this error. If you need to perform actions in one data.fs file from two or more processes: use ZEO.

+3
source

Source: https://habr.com/ru/post/1341456/


All Articles