Is shelve in Python thread safe?
NickName:Tianyang Li Ask DateTime:2011-03-04T10:52:25

Is shelve in Python thread safe?

Is shelve in Python used for data persistence thread safe? If not, what's a good alternative?

Copyright Notice:Content Author:「Tianyang Li」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5189137/is-shelve-in-python-thread-safe

Answers
Mahmoud Abdelkader 2011-03-04T08:29:42

From the standard library documentation about the Shelve module, under the heading Restrictions:\n\n\n The shelve module does not support\n concurrent read/write access to\n shelved objects. (Multiple\n simultaneous read accesses are safe.)\n\n\nI would assume that it's probably implementation dependent and in which case, in order to be sure, I would conclude that it certainly is not thread safe.",


Andreas Jung 2011-03-04T03:04:58

Alternatives: ZODB\n\nhttp://www.zodb.org/",


More about “Is shelve in Python thread safe?” related questions

Is shelve in Python thread safe?

Is shelve in Python used for data persistence thread safe? If not, what's a good alternative?

Show Detail

How to deepcopy shelve objects in Python

Is it possible to deepcopy a shelve object in Python? When I try to deepcopy it, I get the following error: import shelve,copy input = shelve.open("test.dict", writeback=True) input.update({"key1"...

Show Detail

What thread-safe data persistence objects are available in Python for data persistence?

What Python thread-safe data persistence objects are available for data persistence? I need something that's similar to shelve. It's best if I can just change only a little bit of code instead of re-

Show Detail

Python3 shelve items iterator for multiprocessing

I am trying to analyse a large shelve with multiprocessing.Pool. Being with the read-only mode it should be thread safe, but it seams that a large object is being read first, then slowwwwly dispatc...

Show Detail

Is there an easy way to use a python tempfile in a shelve (and make sure it cleans itself up)?

Basically, I want an infinite size (more accurately, hard-drive rather than memory bound) dict in a python program I'm writing. It seems like the tempfile and shelve modules are naturally suited fo...

Show Detail

Shelve module in Python 3.1.1

I'm new to Python and learning through the O'Reilly "Learning Python" series. I'm stuck on a shelve example and can't figure out why the program doesn't work. I'm trying to build some sample data...

Show Detail

Reduce Python shelve size

I'm using the shelve module with gdbm to store Python objects. I understand that shelve uses pickle to store the objects. Unfortunately, the sizes of my shelves are too large. I found this solutio...

Show Detail

Python shelve leak?

It seems that when overwriting a key in a shelve, under certain circumstances the shelve size unexpectedly keeps growing larger. It is as if some data in a shelve ends up not having a reference to ...

Show Detail

python shelve: same objects become different objects after reopening shelve

I am seeing this behavior using shelve: import shelve my_shelve = shelve.open('/tmp/shelve', writeback=True) my_shelve['a'] = {'foo': 'bar'} my_shelve['b'] = my_shelve['a

Show Detail

shelve object and python dictionary

I am not sure this is a bug of the shelve object, but it is still quite odd behavior. If you store a dictionnary object in a shelve object, it seems that you cannot modify easely the associated

Show Detail