I have some legacy python code that using pypar and mpich2 to transmit data between multiple nodes. For some reason the data is kept in shelves and pypar wants to pickle the shelve to send it to other nodes. Pickling shelves is not allowed. So I want to convert from shelve to something I can send via pypar which pickles it before sending to other nodes. Any suggestions? Could I convert the shelve to json and pickle that?
Share
Try converting the shelve to a
dict()and then pickling it:Updated: (Response to a question in comments): A
dictcan copy the key-values from any mapping object, so if that object implements the methodskeysand__getitem__it will work. Since a shelve is a mapping object, thedictcopy constructor can read the key-values from the shelve, then you can pickle the resulting dict and ship it to other hosts.The example below shows the minimal interface
dictrequires to copy an object:Output
Update: To add the contents of a dict back to a shelve, use
update():