This documentation is for an old version of IPython. You can find docs for newer versions here.
PickleShare - a small ‘shelve’ like datastore with concurrency support
Like shelve, a PickleShareDB object acts like a normal dictionary. Unlike shelve, many processes can access the database simultaneously. Changing a value in database is immediately visible to other processes accessing the same database.
Concurrency is possible because the values are stored in separate files. Hence the “database” is a directory where all files are governed by PickleShare.
from pickleshare import * db = PickleShareDB('~/testpickleshare') db.clear() print "Should be empty:",db.items() db['hello'] = 15 db['aku ankka'] = [1,2,313] db['paths/are/ok/key'] = [1,(5,46)] print db.keys() del db['aku ankka']
This module is certainly not ZODB, but can be used for low-load (non-mission-critical) situations where tiny code size trumps the advanced features of a “real” object database.
Installation guide: easy_install pickleshare
Author: Ville Vainio <email@example.com> License: MIT open source license.
The main ‘connection’ object for PickleShare database
Return a db object that will manage the specied directory
Get a convenient link for accessing items
Compress category ‘hashroot’, so hset is fast again
hget will fail if fast_only is True for compressed items (that were hset before hcompress).
Get all data contained in hashed category ‘hashroot’ as dict
All keys in DB, or all keys matching a glob
Removes all, or specified items from cache
Use this after reading a large amount of large objects to free up memory, when you won’t be needing the objects for a while.
Wait (poll) for a key to get a value
Will wait for maxwaittime seconds before raising a KeyError. The call exits normally if the key field in db gets a value within the timeout period.
Use this for synchronizing different processes or for ensuring that an unfortunately timed “db[‘key’] = newvalue” operation in another process (which causes all ‘get’ operation to cause a KeyError for the duration of pickling) won’t screw up your program logic.