I'm trying to use a generic object called 'Memory' to temporary store a value that is writen by a process called 'Writer_process' and readed by 'Reader_process' but reader return only the original value stored in 'Memory'.
import multiprocessing
import time
class Writer_process(multiprocessing.Process):
def __init__(self, val, memory):
super().__init__()
self.val = val
self.memory = memory
def run(self):
cont = 0
while True:
cont += self.val
self.memory.num = cont
time.sleep(1)
class Reader_process(multiprocessing.Process):
def __init__(self, val, memory):
super().__init__()
self.val = val
self.memory = memory
def run(self):
while True:
print(self.memory.num)
time.sleep(self.val)
class Memory():
num = 0
if __name__ == '__main__':
memory = Memory()
writer = Writer_process(1, memory)
reader = Reader_process(1, memory)
writer.start()
reader.start()