concurrent access to dbms (was best way to store dbm records?)
Michael B. Allen
mballen at NOSPAM_erols.com
Sun Oct 8 05:30:40 EDT 2000
Shelve works great Tim, thanks. I have implemented this and it works very
well for my purposes.
I may have a different issue however. The docs on shelve(and I would imagine
dbm's in general) report that you cannot concurrently read from it if it is
open by a writer. If I have interpreted the docs correctly this is true even
if it is only open by a single writer.
Can I have may readers with one writer or might this corrupt the database?.
Or in the worst case will it mearly display possibly incomplete information
to a reader?
In my case I don't care if readers get realtime info. Can I just
periodically make a copy of the dbm for readers?
Also, how many records can I put in a dbm without taking a big performance
hit? 10000?
Thanks,
Mike
Tim Roberts wrote in message <9f2vtss06scg26psv7gvfv8agt68jc91h3 at 4ax.com>...
>"Michael B. Allen" <mballen at NOSPAM_erols.com> wrote:
>>Hi!
>>
>>I was wondering what the best/simplest way to store dbm records is? This
is
>>how I am currently adding records:
>>
>> # create dbm record
>> p = '102'
>> s = getfield(msg, 'from')
>> a = getfield(msg, 'authors')
>> v = getfield(msg, 'version')
>> d = getfield(msg, 'description')
>> x = getfield(msg, 'fixes')
>> o = getfield(msg, 'obsoletes')
>> r = getfield(msg, 'requires')
>> f = getfield(msg, 'flags')
>> dbmrecord = (a,v,d,x,o,r,f)
>> db[p] = `dbmrecord`
>
>A shelve can do this all for you. A shelve is just a dbm that holds
>pickled objects. Create a class to hold the data:
>
> class EMailIndex:
> self.key = ''
> ...
>
> fields =
> 'from',
> 'authors',
> 'version',
> 'description',
> 'fixes,'
> 'obsoletes',
> 'requires',
> 'flags'
> )
>
> idx = EMailIndex()
> idx.key = '102'
> for name in fields:
> idx.__dict__[name] = getfield(msg, name)
>
> db = Shelve.open( dbname, 'w' )
> db[idx.key] = idx
> db.close()
>
>Later, you can get the object back intact.
>
> >>>db = Shelve.open( dbname, 'r' )
> >>>xxx = db['102']
> >>>xxx.authors
> ds-0.1
>
>--
>- Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list