[Zope] help with zodb
Jeff Hoffman
jeff.hoffman@goingv.com
Thu, 2 Mar 2000 18:58:38 -0500 (EST)
On Thu, 2 Mar 2000, Garrett G. Hodgson wrote:
> thank you for your help. forgive my being obtuse, but i'm still not
> getting it.
Turns out it was me that was being obtuse. See below.
> > Only one process can access a ZODB at a time. You have two. The first is
> > Zope, and the second is the external method.
>
> ok. by "a ZODB" do you mean that the call in my external method
> is trying to reopen the ZODB zope is using? i'd assumed i was
> crating another one, with a separate FileStorage.
This is the detail I did not notice, previously. I thought you were trying
to store objects in your Zope ZODB; I didn't notice that the filename you
were passing to FileStorage was not Data.fs.
Sorry.
[snip]
> so, one more try. given the following external method:
>
> import ZODB, ZODB.FileStorage
>
>
> def GetPeople( self ):
> "Return list of people in DB"
>
> db = ZODB.DB( ZODB.FileStorage.FileStorage( 'TestDB.fs' ) )
> connection = db.open()
> root = connection.root()
> people = []
> for key in root.keys():
> people.append( root[ key ] )
> return people
>
> if __name__ == '__main__':
> for person in GetPeople( None ):
> print person.name, 'is', person.age, 'years old'
>
>
> referenced from a DTML Method:
>
> <dtml-in "GetPeople()">
> <dtml-var name> is <dtml-var age> years old.<br>
> </dtml-in>
>
> when i restart zope and view the method, it works once, but shows
> no persons. the second time, it fails with the traceback.
I don't understand why the problem is manifesting as it is, but I got your
code to work by modifying your code as follows:
- for key in root.keys():
- people.append(root[key])
+ connection.close()
- return people
Opening a connection without closing it is a Bad Idea. I just can't figure
out what this has to do with the lock file on the database. I figured when
I closed the connection it was deleting the lock, but this is not so. So,
I remain confused. ;-)
> what do i change to make it work?
Hope this helps!
--Jeff
---
Jeff K. Hoffman 704.849.0731 x108
Chief Technology Officer mailto:jeff@goingv.com
Going Virtual, L.L.C. http://www.goingv.com/