Sharing data between two processes with ProcessPoolExecutor

Viewed 41

I'm trying to share data between two processes. I have two classes classA and classB. The classA uses ProcessPoolExecutor to execute a function in classA. Since ProcessPoolExecutor does not allow pickling dictionaries, I used redis to share memory and the data between the classA and classB.

I use the following code to save data in classB.

self.redisClient.hmset("person1-hash", {
                "name": "jane",
                "age": 20
            })

In the classA, I'm checking if the key person1-hash is present. If so,I'm trying to retrieve the data.

if self.redisClient.hexists("person1-hash", "name"):
    data = json.loads(self.redisClient.hget('person1-hash').decode("utf-8"))

Unfortunately, it always turns out to be false. What am I missing?

0 Answers
Related