On Fri, 28 Oct 2005 00:17:54 +0800, "Neville C. Dempsey" <[EMAIL PROTECTED]> wrote: >Why does this python program fail to read record "6000000"? > >#!/usr/bin/env python >import bsddb # twiceopen.py > >key="6000000" >btf=bsddb.db.DB_INIT_THREAD > >list1=bsddb.btopen("twiceopen.tbl",btflags=btf) >list1[key]="we have the technology" > >list2=bsddb.btopen("twiceopen.tbl",btflags=btf) >#print "key:",key,"val:",list2[key] # doesn't work... >print "first:",list2.first() # also fails first time... > >list1.close() >list2.close() > >Maybe the solution needs one of: > db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_THREAD|db.DB_INIT_CDB
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. Jp -- http://mail.python.org/mailman/listinfo/python-list