I want to use multiprocessing for my project at school but I have a problem with shared variables between multiple processes. To simulate the problem, I made some code to show you:
import multiprocessing
import ctypes
import time
def function1():
global value
while True:
value.value += 1
time.sleep(1)
def function2():
global value
while True:
value.value += 1
time.sleep(1)
if __name__ == "__main__":
manager = multiprocessing.Manager()
value = manager.Value("i", 0)
process1 = multiprocessing.Process(target=function1)
process2 = multiprocessing.Process(target=function2)
process1.start()
process2.start()
while True:
print(value.value)
time.sleep(1)
this is the error message that I get:
NameError: name 'value' is not defined
Can someone help me with this please? Thank you