Python shelve dbm.error?

I am trying to add a dicts file to a shelf file:

>>> d = shelve.open('index.shelve') >>> d <shelve.DbfilenameShelf object at 0x21965f0> >>> print(list(d.keys())) [] >>> d['index'] = index Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/bns/rma/local/python/lib/python3.1/shelve.py", line 124, in __setitem__ self.dict[key.encode(self.keyencoding)] = f.getvalue() _dbm.error: cannot add item to database 

the index is somewhat large, but not huge. This is essentially an array of floats:

 >>> len(index) 219 >>> a = [ index[k][k1] for k in index for k1 in index[k] ] >>> len(a) 59995 >>> all([ type(x) is float for x in a ]) True 

What is this mistake? Also, is there somewhere inside the module or module documentation I have to look to find out more about what the error represents? The error message is not very informative, at least for me :).

+4
source share
1 answer

I had the same problem with the dbm module, it is reproducible in my code base, but I can not reproduce it in an isolated test.

My impression is that there is a lock that prevents writing while reading the database. In my case, db ~ 200 Kb, with ~ 10 keys and inserting time.sleep(1) will solve the problem, hinting at some kind of asynchronization process that was not completed at the moment db[key] = value .

+1
source

Source: https://habr.com/ru/post/1339693/


All Articles