I just need to send a command from one process to another, but I wanted to understand why when modifying the variable within a function, it does not appear in another function.
from multiprocessing import Process
import time
ComandoSerial = 0
class teste():
var = 0
def __init__(self):
self.var2 = 0
def funcao(self):
self.__class__.var = 1
self.var2 = 1
def funcao2(self):
self.__class__.var = 2
self.var2 = 2
def funcao3(self):
self.__class__.var = 3
self.var2 = 3
def retorna(self):
return self.__class__.var
def retorna2(self):
return self.var2
test = teste()
def Teste1():
test.funcao3()
def Teste2():
time.sleep(0.2)
print("VALOR = ", test.retorna())
p = Process(target= Teste1)
p1 = Process(target= Teste2)
def main():
p.start()
p1.start()
p.join()
p1.join()
if __name__ == "__main__":
main()
The problem is that I put the value 3, but reading it always returns 0.