ZEO ZODB database - run locally not working

706 views Asked by At

I tried looking at the documentation for running ZEO on a ZODB database, but it isn't working how they say it should. I can get a regular ZODB running fine, but I would like to make the database accessible by several processes for a program, so I am trying to get ZEO to work.

I created this script in a folder with a subfolder zeo, which will hold the "database.fs" files created by the make_server function in a different parallel process:

CODE:

from ZEO import ClientStorage
import ZODB
import ZODB.config
import os, time, site, subprocess, multiprocessing

# make the server in for the database in a separate process with windows command
def make_server():
    runzeo_path = site.getsitepackages()[0] + "\Lib\site-packages\zeo-4.0.0-py2.7.egg\ZEO\\runzeo.py"
    filestorage_path = os.getcwd() + '\zeo\database.fs'
    subprocess.call(["python", runzeo_path, "-a", "127.0.0.1:9100", "-f" , filestorage_path])

if __name__ == "__main__":
    server_process = multiprocessing.Process(target = make_server)
    server_process.start()
    time.sleep(5)
    storage = ClientStorage.ClientStorage(('localhost', 9100), wait=False)
    db = ZODB.DB(storage)
    connection = db.open()
    root = connection.root()

the program will just block at the ClientStorage line if the wait=False is not given.

If the wait=False is given it produces this error:

Error Message:

Traceback (most recent call last):
  File "C:\Users\cbrown\Google Drive\EclipseWorkspace\NewSpectro - v1\20131202\2 - database\zeo.py", line 17, in <module>
    db = ZODB.DB(storage)
  File "C:\Python27\lib\site-packages\zodb-4.0.0-py2.7.egg\ZODB\DB.py", line 443, in __init__
    temp_storage.load(z64, '')
  File "C:\Python27\lib\site-packages\zeo-4.0.0-py2.7.egg\ZEO\ClientStorage.py", line 841, in load
    data, tid = self._server.loadEx(oid)
  File "C:\Python27\lib\site-packages\zeo-4.0.0-py2.7.egg\ZEO\ClientStorage.py", line 88, in __getattr__
    raise ClientDisconnected()
ClientDisconnected

Here is the output from the cmd prompt for my process which runs a server:

------
2013-12-06T21:07:27 INFO ZEO.runzeo (7460) opening storage '1' using FileStorage

------
2013-12-06T21:07:27 WARNING ZODB.FileStorage Ignoring index for C:\Users\cab0008
\Google Drive\EclipseWorkspace\NewSpectro - v1\20131202\2 - database\zeo\databas
e.fs
------
2013-12-06T21:07:27 INFO ZEO.StorageServer StorageServer created RW with storage
s: 1:RW:C:\Users\cab0008\Google Drive\EclipseWorkspace\NewSpectro - v1\20131202\
2 - database\zeo\database.fs
------
2013-12-06T21:07:27 INFO ZEO.zrpc (7460) listening on ('127.0.0.1', 9100)

What could I be doing wrong? I just want this to work locally right now so there shouldn't be any need for fancy web stuff.

3

There are 3 answers

1
sdupton On

You should use proper process management and simplify your life. You likely want to look into supervisor, which can be responsible for running/starting/stopping your application and ZEO.

Otherwise, you need to look at the double-fork trick to daemonize ZEO -- but why bother when a process management tool like supervisor does this for you.

If you are savvy with relational database administration, and already have a relational database at your disposal -- you can also consider RelStorage as a very good ZODB (low-level) storage backend.

0
koivumat On

In Windows you should use double \ instead of a single \ in the paths. Easy and portable way to accomplish this is to use os.path.join() function, eg. os.path.join('os.getcwd()', 'zeo', 'database.fs'). Otherwise a similar code worked ok for me.

0
FanFani4 On

Had same error on Windows , on Linux everything OK ... your code is ok , to make this to work change following C:\Python33\Lib\site-packages\ZEO-4.0.0-py3.3.egg\ZEO\zrpc\trigger.py ln:235

self.trigger.send(b'x')

C:\Python33\Lib\site-packages\ZEO-4.0.0-py3.3.egg\ZEO\zrpc\client.py ln:458:459 - comment them

here is those lines:

if socktype != socket.SOCK_STREAM:

    continue