Skip to content
Advertisement

Is there a way to make a class add multiprocessing shared values?

I have created a class where all the functions work and can be put into different processes and edited. All of the functions work except the add value function. This is my class:

JavaScript

Which can then be used correctly with these lines of code in the main function:

JavaScript

When I go to use the addValue function in my code, the first process works great and can return the value when the get function is called. However, when I go to call the get function for the second process it fails. One of my ideas on a solution is to use the multiprocessing Queue method and have both processes add the value. Although, I have a feeling even if both functions have added the value it will not change if one of them changes the value. Is what I am trying to accomplish do-able, or should I just try to initialize all of my variables from the start?

Advertisement

Answer

I found that the only way to do this is to use a multiprocessing dictionary, I have posted the working example of an initializer and creator below.

JavaScript

then if you wanted to add a regular value:

JavaScript

This honestly was probably one of the original reasons for the manager dictionary. Anyways, I hope if anyone needs this information and stumbles across this post it helps.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement