UltraDict
UltraDict copied to clipboard
Added as_pure_dictionary method
I recently had a problem with pickling and unpickling UltraDict instances with recurse=True. After some wild bug hunting I realized that accessing UltraDict's data attribute/property didn't convert nested UltraDict items also to basic dictionaries, thus breaking pickling and unpickling actions, other than stopping following updates from syncing.
I added the method as_pure_dictionary
, with proper unit tests, and tested them in production with one single shared memory between 6 high frequency realtime processes both using reads and writes in different parts of the same UltraDict with recurse=True enabled, with success!
Basic usage for me in that project was something like this pseudocode:
ultra = UltraDict(
{
"1": "hello",
"2": 5,
"3": {
"1": 1,
"2": {
"1": True,
"2": None,
"3": [1, 2, 3]
},
"3": [4, 5, 6, {"7": 8}]
}
},
recurse=True,
create=True
)
as_dict = ultra.as_pure_dictionary()
db.save(pickle.dumps(as_dict))
# Saving it to database
# Some time later, on the next app opening
as_dict = pickle.loads(db.load())
ultra = UltraDict(as_dict, recurse=True, create=True)
# And start reusing it as I left it!
ultra["2"] = 18
Hope it sounds good for you, and hope it helps somebody as well as it helped me!
If you have questions let me know, I'm happy to fix things if they aren't properly good enough :)
Thanks for your pull request. I expect to merge this on the weekend.
Hi, any problems regarding this pull request? Should I fix something?
Hey, sorry, no problem at all. I wanted to merge but then there were issues with my build pipeline as I added some performance tests (to detect performance regressions) which are not working yet and never had the time to finish it. I'll try to do it asap. Sorry again and thanks for your contribution. Much appreciated.
If you need help for contributions I'm here to help if needed :)