[ZODB-Dev] Multiple applications accessing one storage

Monty Taylor mordred@inaugust.com
16 May 2001 11:54:18 -0400


Toby Dickenson <tdickenson@devmail.geminidataloggers.co.uk> writes:

> On 16 May 2001 10:50:01 -0400, Monty Taylor <mordred@inaugust.com>
> wrote:
> 
> >oivvio polite <ol1@v10a.com> writes:
> >
> >> If I have one application running that is accessing Foo.fs and start up
> >> a second application trying to access Foo.fs I get an error message 
> >> saying something about a lock file. 
> >> 
> >> This is not very surprising.
> >> 
> >> But what should I do about it? Is this where I should start looking into
> >> ZEO or is there an easier workaround?
> >
> >I'd start looking into ZEO. ZEO itself is fairly simple to get
> >working, and gives you loads of benefits. I run all my Zope
> >installations under ZEO, even if they will only be running on a single
> >machine.
> 
> Can you explain some of the benefits for a single machine system
> please

If you're running ZEO, you can make multiple connections to the
ZODB. The upshot of this is that you can write utility scripts to do
things in the ZODB. (You can basically just import Zope at the top and
it makes the connection for you...) Without ZEO, you'd most likely
wind up writing whatever script you wanted as an External Method and
then invoking it from a URL. (Not the best for cron jobs) 

The other upshot is that you can connect to Zope via command line
python: (with or without the python debugger)

--start zdebug.py--
import ZServer
import Zope
import pdb
from AccessControl.SecurityManagement import newSecurityManager

app = Zope.app()
uf=app.acl_users
user=uf.getUser('mordred').__of__(uf)
newSecurityManager(None, user)
--end-- (*DISCLAIMER* I took this code from some of the guys at DC. I
didn't write it. I probably could have -- it's all of 8 lines and the
bare bones basics of making a connect -- but I
don't want to take any credit where it's not due)

run that with python -i zdebug.py and you can walk around in the
tree. You'll need to have environment variables set, so I have a
little shell script...

--start zdebug.sh--
ZOPE_HOME=/zope/dist/2.3.2
SOFTWARE_HOME=$ZOPE_HOME/lib/python
INSTANCE_HOME=/zope/instances/zi-1.0
PYTHONPATH=$INSTANCE_HOME:$SOFTWARE_HOME:$ZOPE_HOME:.:/zope/lib
export ZOPE_HOME INSTANCE_HOME SOFTWARE_HOME PYTHONPATH
cd $ZOPE_HOME
exec /usr/bin/python -i /home/mordred/zdebug.py
--end zdebug.sh--

You can now play with Zope just like you play with other python.

I'm running a script currently at work (I can't tell you too many
details) which runs hourly bulk-loading of data from external
feeds. To do something like that, you can take the above scripts as a
starting point, and just start writing your code below it. Like...

--start zaddfolder.py--
import ZServer
import Zope 
# import pdb don't need the debugger for a utility script
from AccessControl.SecurityManagement import newSecurityManager

app = Zope.app()
uf=app.acl_users
user=uf.getUser('mordred').__of__(uf)
newSecurityManager(None, user)

app.manage_addFolder('testfolder')
get_transaction().commit()
--end--

Obviously, you'll normally want to script things more complex than
adding a folder, but perhaps you get the idea. 

Besides, if you develop everything under ZEO, you're already set for
scalability sake. And it really doesn't take but 5 extra minutes of
effort. (You have to start the StorageServer and then a client) 

BTW - If you're using the latest ZEO, you don't need to import ZServer
in those scripts. 

Monty

PS. If anyone thinks that info helps, please let me know and I'll try
to clean it up a bit and write a How-To.