Pregunta

I have a site where every time I try to open the database while the server was running, it displays an error that the database is already open by a different process.

The problem is that I have some scripts that could be scheduled with cron to check the database, or even just using pshell while the server is running.

As of now, it seems impossible to open the database from different processes, while the doc actually says that it's possible to have multiple connections to the database.

This issue forces me to run just one script/process at a time, including the server.

¿Fue útil?

Solución

ZODB, in its default configation, is an in-process object database. You can, however, use a client-server model to share it across processes.

You have 3 options here:

  • Use ZEO to create a dedicated process to share the ZODB storage(s). There used to be a Pyramid cookbook entry on Using ZODB with ZEO with Pyramid-specific instructions, but take into account that it was removed in December 2013 for being out-of-date. To me the instructions look reasonably accurate still, but I haven't tested them.
  • Use RelStorage to store the object database in Oracle, MySQL or PostgeSQL.
  • Use NEO to use MySQL as a distributed backend. Caveat: this platform has not (yet) been made compatible with Python 3, but the project is actively being worked on (as of November 2018) so this could be in the cards.

Otros consejos

You can use RelStorage.

pip install RelStorage

... or add to setup.py requires:

requires = [
...
RelStorage',
]

Change developer.ini in section [app:main]:

[app:main]
...
zodbconn.uri = zconfig://%(here)s/relstorage.conf

Create a file 'relstorage.conf' with this content:

%import relstorage
<zodb main>
  <relstorage>
    <postgresql>
      # The dsn is optional, as are each of the parameters in the dsn.
      dsn dbname='zodb' user='zodbuser' host='yourhostname.net' password='YOURpassowrd'
    </postgresql>
  </relstorage>
</zodb>

According settings the 'relstorage.conf' must placed in same folder with 'developer.ini'

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top