Skip to content Skip to sidebar Skip to footer

Zc.lockfile.LockError In ZODB

I am trying to use ZODB 3.10.2 on my web server which is running Debian and Python 2.7.1. It seems like every time I try to access the same database from 2 different processes, I g

Solution 1:

The ZODB does not support multi-process access. This is why you get the lock error; the ZODB file storage has been locked by one process to prevent other processes altering it.

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

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

Another option is to use RelStorage, which stores the ZODB data in a relational database. RelStorage supports PostgreSQL, Oracle and MySQL backends. 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 up-front setup work but can outperform ZEO in many scenarios.


Solution 2:

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


Solution 3:

## Let the program run once (if it's already running, don't run it again)
## Run the program, open the form
import sys
import zc.lockfile
try:
    lock = zc.lockfile.LockFile('lock', content_template='{pid};{hostname}')
    if __name__ == '__main__':
        mainForm()
except zc.lockfile.LockError:
    sys.exit()

## zc.lockfile thanks
## https://pypi.org/project/zc.lockfile/#detailed-documentation

Post a Comment for "Zc.lockfile.LockError In ZODB"