ZODB

38 views
Skip to first unread message

Dirk Makowski

unread,
Aug 20, 2011, 6:02:54 AM8/20/11
to pylons-...@googlegroups.com
Hello,

working with ZODB has brought up some questions. They are related to Pyramid which is why I'd like to ask/discuss them here.

1) The ZODB docs state that the db needs some kind of vacuum from time to time, which is done by db.pack(). From a Pyramid app, how can I obtain that handle to the database connection? As I understand it, that handle is hidden somewhere inside PersistentApplicationFinder And would it be advisable to do a pack from inside the Pyramid app, when some of the stored objects my be in use by the app itself, like those objects in traversal's lineage? (Deleting such will have strange effects, I experienced that already ;)

2) The WSGI pipeline as described in the tutorials (and the paster template) use egg:repoze.zodbconn#closer. Would it be possible in Pyramid to use egg:repoze.zodbconn#connector instead (or additionally?) Connector would put the connection in the WSGI environment.

3) By request.root we have access to the root object of the resource tree for traversal. Now, appmaker() receives as argument "zodb_root". Is it possible to obtain "zodb_root" from elsewhere, so I could store objects in ZODB that are not part of the resource tree?

I hope you don't mind me asking so many questions.
Thanks for your patience and help.
Dirk

Danny Navarro

unread,
Aug 22, 2011, 4:38:31 AM8/22/11
to pylons-...@googlegroups.com
On Sat, Aug 20, 2011 at 12:02 PM, Dirk Makowski
<dirk.m...@googlemail.com> wrote:
> Hello,
> working with ZODB has brought up some questions. They are related to Pyramid
> which is why I'd like to ask/discuss them here.
> 1) The ZODB docs state that the db needs some kind of vacuum from time to
> time, which is done by db.pack(). From a Pyramid app, how can I obtain that
> handle to the database connection? As I understand it, that handle is hidden
> somewhere inside PersistentApplicationFinder And would it be advisable to do
> a pack from inside the Pyramid app, when some of the stored objects my be in
> use by the app itself, like those objects in traversal's lineage? (Deleting
> such will have strange effects, I experienced that already ;)

I never have used it but I've heard people in the Plone/Zope world
running repozo script through a cron job for automatic packing and
backups of ZODB:
http://wiki.zope.org/zope2/RepozoPy

I think there were some discussioin about deprecating repozo but I
think it still comes with the latest ZODB release.

> 2) The WSGI pipeline as described in the tutorials (and the paster template)
> use egg:repoze.zodbconn#closer. Would it be possible in Pyramid to use
> egg:repoze.zodbconn#connector instead (or additionally?) Connector would put
> the connection in the WSGI environment.

I don't understand this question.

> 3) By request.root we have access to the root object of the resource tree
> for traversal. Now, appmaker() receives as argument "zodb_root". Is it
> possible to obtain "zodb_root" from elsewhere, so I could store objects in
> ZODB that are not part of the resource tree?

You can directly connect to ZODB as described in ZODB docs to get the root:
http://www.zodb.org/documentation/tutorial.html#configuration
This is independent of Pyramid and PasterScript.

Remember that in order to connect to ZODB with more than 1 process you
need to run ZODB in ZEO mode.

With repoze.zodbconn you can also use the same configuration you have
in your Pyramid application to get the ZODB root.

> I hope you don't mind me asking so many questions.
> Thanks for your patience and help.
> Dirk

In my experience the best to way to learn about how these ZODB
connections work with Pyramid is by setting an ipdb trace where the
Pyramid WSGI is configured and playing with the ZODB API at different
connection levels.
http://pypi.python.org/pypi/ipdb

Hope it helps.

>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/I8y_rHZj8L0J.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>

--
Danny Navarro  |  http://dannynavarro.net

Dirk Makowski

unread,
Aug 22, 2011, 4:53:37 PM8/22/11
to pylons-...@googlegroups.com
Many thanks for your answer and the links, esp. ipdb.

About ZODB I have found out this:

In a Pyramid application there's a method named "appmaker()" which creates the resource tree as children of the ZODB's root object. This zodb_root is provided by an instance of a PersistentApplicationFinder, which manages the creation of a database instance and opening and closing the connection. This db instance the finder stores in its attribute"db", and this instance is needed to pack the database with "db.pack()". The examples in Pyramid's manual create the finder locally inside main(), so other modules have no access to it. Maybe I'll create the finder inside module "resources.py" from which it could be imported.

A more detailed description I have written in chapter "The Database Handle" here: http://3amcode.de//pharaoh/Cms/pharaoh/01-learning-pyramid/00300-zodb-the-zope-object-database/

Dirk
Reply all
Reply to author
Forward
0 new messages