Jean-Paul Calderone exarkun at divmod.com
Thu Oct 27 18:30:26 CEST 2005

On Fri, 28 Oct 2005 00:17:54 +0800, "Neville C. Dempsey" <nevillednz.python at 3ttechnology.com> wrote:
>Why does this python program fail to read record "6000000"?
>#!/usr/bin/env python
>import bsddb # twiceopen.py
>list1[key]="we have the technology"
>#print "key:",key,"val:",list2[key] # doesn't work...
>print "first:",list2.first() # also fails first time...
>Maybe the solution needs one of:

You really want to use transactions if you are going to access a database concurrently.  So that means DB_INIT_TXN.  Now since you need transactions, you need an environment, so you want to let bsddb create whatever environment files it needs.  So that means DB_CREATE.  Now since there's an environment, every process but the first to open it needs to *join* it, rather than opening it in the usual way.  So that means DB_JOINENV for all but the first open call.

Except I don't think btopen() supports half these operations.  You really want to use bsddb.db.DBEnv and bsddb.DB.  Or a library that wraps them more sensibly: <http://divmod.org/users/viewcvs.twistd/trunk/atop/store.py?rev=9302&view=markup>.  You probably don't want everything there, but the DatabaseEnvironment class (and supporting code) should be useful.


More information about the Python-list mailing list