Search code examples
pythonpyramidzodb

Accessing ZODB from two processes


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.


Solution

  • 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.