[ZODB-Dev] experimenting with Standalone ZODB...
enri@users.sourceforge.net
enri@users.sourceforge.net
18 Oct 2001 21:58:38 +0200
Hi all,
I'm experimenting a bit with ZODB... Here's what's going on.
I wrote a "db load" script which creates a ZODB from a flat file. The
objects to be stored are Stock prices (with price variations histories
too). The Stock is modeled using a class with some attributes (id,
description, ...) and the Stock price's past variations, implemented
using a PersistentMapping with an integer (the date) as a key and a
float as value. There is only a root object which is a
PersistentMapping with a stock instance's id as key and a stock
instance as value. This script imports the object from a 250MB file
and everything works (I don't need versions so I used a Packless
storage).
Then i wrote a sort of 'datadig' program which, given a
persistentmapping, prints on stdout every attribute of its items.
This program eats all the memory of my machine, finally trashing it
(the 1st time I ran it I had to unplug the power ;-) )
I can't figure out what's going on... Can any1 take a look to the code
below and give me any advice, please?
----------> stock class def <----------
class PProduct(Persistence.Persistent):
def __init__(self, code):
self.id = code
self.description = ''
self.lastUpdate = None
self.history = PersistentMapping()
----------> datadigger <----------
from bsddb3Storage.Packless import Packless
from ZODB import DB
import Product, graph
storage = Packless(name='riskmap', env='riskmap')
db=DB(storage)
c=db.open()
r=c.root()
print 'db opened'
import time
t = time.time()
print "avaliable products: %d (in %fs)" % (len(r['products'].keys()), time.time() - t)
t = time.time()
print "avaliable products: %d (in %fs)" % (len(r['products'].keys()), time.time() - t)
#import sys
#sys.exit(0)
print 'before'
a = r['products'].keys()
print 'after'
counter = 0
for k in a:
counter = counter + 1
print '*** examining product: %d - %s ***' % (counter, r['products'][k].id)
for attr in filter(lambda x: x[0] != '_',
dir(r['products'][k])):
print "%s: %s" % (attr, getattr(r['products'][k], attr))
for date in r['products'][k].history.keys(): pass #print date, r['products'][k].history[date]
----------> END <----------
I'm clueless... It seems that this script keeps every item of
r['products'] (i.e. the root object) in memory, trashing the machine.
What did i miss?
Thanks in advance,
enrico
--
Enrico Sirola <enri@users.sourceforge.net>
gpg public key available from wwwkeys.pgp.net
Key fingerprint = B446 7332 ED55 BC68 5FE8 DE0F 98DF EC86 377F E07F