shelve databases

Joe Francia usenet at soraia.com
Fri May 23 17:11:06 EDT 2003


soporte at prsystem.com wrote:

> Hello:
> I have a question about the shelve module and the multiuser environment. I
> dont know how to implement a multiuser database with shelve, how to lock
> and unlock for example.
> I like to use shelve because its part of python and this simplify the work
> of install my program, and its usefull for my the use of python objects in
> a database.
> Regards,
> Pablo
> 

I'm not sure it's a good idea to try.  From the Python docs:

"The shelve module does not support concurrent read/write access to 
shelved objects. (Multiple simultaneous read accesses are safe.) When a 
program has a shelf open for writing, no other program should have it 
open for reading or writing. Unix file locking can be used to solve 
this, but this differs across Unix versions and requires knowledge about 
the database implementation used."

If you are going to do multiuser stuff, you may want to check out the 
excellent Python bindings for the Berkeley database: 
http://pybsddb.sourceforge.net/  It doesn't quite meet your requirements 
of being part of Python**, but it does offer a replacement for the 
shelve module (dbshelve) that can take advantage of the full 
capabilities of the underlying database, and will probably save you 
quite a bit of development work.

** As late as 2.2, however 2.3 includes PyBSDDB

jf





More information about the Python-list mailing list