-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nest assignment is ignored smd['some-key']['x'] #58
Comments
Was baffled by this limitation as well. As a work around, how about juggling the nested object?
edit: added more comments |
Is there a better fix for this? The "juggling" above throws an error. |
Hey, Could you show the error you're getting there? |
client is a initialized class, key is a str smd = SharedMemoryDict(name="123", size=1024)
smd["data"]
def add_to_data():
temp = smd["data"]
temp[key] = {
"key": key,
"client": client,
}
smd["data"] = temp
def add_to_data()
|
I tested it without client, that seems to be the issue. I'm not quite sure how to go about this |
Got this error when using the built in JSONSerializer instead, as I read pickle has problems with local objects:
|
I think this is the problem you've got there as it relates to the fact that you cannot assign custom objects (that cannot be pickled) as values. Change your client type to something more common - such as str or int - and you'll get the result.
What is the reason for passing such client object between the processes? Does it hold some kind of important information you want to update? |
Yes, the client class has functions and data that I need to access in other files. So simply using a string would not really work.. I tried using dill (a drop in replacement for pickle with more support for custom types), but I face different issues there. I could store the clients in a local dict in that file, and then send read/write commands through shared memory, but that would really be pain, I'm trying to find a clean solution. |
How about refactoring class data out to DTOs that can be passed around through the SharedMemoryDict functionality? I think that was the core concept behind shared_memory objects. |
That would kinda be a little complex, the functions need the context of the client class to work properly, as there are multiple clients initialized |
Sorry, but I'm afraid I cannot help any further since I do not possess enough information about the logic you're trying to implement. It seems to be out of SharedMemoryDict scope. |
All good, it's an issue with pickle/dill. |
from shared_memory_dict import SharedMemoryDict
smd = SharedMemoryDict(name='tokens', size=1024)
smd['some-key'] = {}
smd['some-key']['x'] = 1 #this statement is ignored
print(smd) #output {'some-key': {}}
The text was updated successfully, but these errors were encountered: