[Zope-dev] connecting server code to the ZODB

Paul Winkler pw_lists at slinkp.com
Mon Nov 8 15:03:26 EST 2004


On Mon, Nov 08, 2004 at 11:22:13AM -0000, Tim Hicks wrote:
> Paul Winkler said:
> 
> >> > What I really want to be able to do from the server code is something
> >> like::
> >> >
> >> >     root = magic_that_gets_me_zodb_root()
> >>
> >> That magic is basically (from memory):
> >>
> >>   import Zope
> >>   Zope.startup()
> >>   root = Zope.app()
> >>
> >> But note that starting up a zope is slow, so you don't want to do that
> >> very often.
> >
> > Well, in this case zope is already running.
> 
> 
> Ok, so I could simply drop the Zope.startup() line and things would be
> fine (and quick), right?

I haven't tried it, but I think doing Zope.app() will try to
acquire a lock on the database and it is already locked by
the running Zope (or ZEO). So I don't think you can do that.


> > I think you should use the existing publisher machinery.
> > Given an SMTPRequest instance foo, you should be able to
> > do foo.traverse(path, response) and get back an object.
> > This monster method is defined in ZPublisher/BaseRequest.py
> 
> 
> What does using foo.traverse() buy me over simply accessing the ZODB
> objects 'by hand', as in root = Zope.app()? 

Well, for one thing it might actually work ;-)

Note, I'm not sure what your code looks like - if you already
have a reference to any persistent object (as long as it's
Traversable which basically anything of interest to you would be),
you can get the root by doing root = someObject.getPhysicalRoot().

> It seems I get security by
> using foo.traverse() - although I'm not sure whether that is really
> necessary for my purposes.  Would it also deal with any ZODB transaction
> stuff for me that I would otherwise have to sort out -
> get_transaction().commit().  If I'm just reading ZODB objects (not
> writing), does the transaction stuff even matter?

I'm afraid I don't know either of those, I've never tried to hook into 
zope from within a ZServer server. 
Generally a transaction runs for the duration of one request,
but I am not clear on who manages that: is it ZPublisher?
It looks like transactions are managed in ZPublisher/Publish.py, but I have
never looked at that code and don't have time to figure it out now.
Sorry.

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope-Dev mailing list