I have two processes going on and I have a class containing a method that modifies a value, as you can see in the code below. The ButtonObject function represents a click, to modify a value. But the question is, why does the change only occur within function 1 and not of function2, or the opposite if we call the function EventButton inside function2? If both use the same instance of the class, if the value of the variable is modified, should not 100 be printed on the two calls to show the value? If someone can explain why this does not happen and what would be the way to "access" the value of the variable in both processes.
#!/usr/bin/python3
from multiprocessing import Process, Queue
class Aplicativo(object):
Comando = 0
def MostraValor(self):
print("VALOR CMD = ", self.__class__.Comando)
def InsereValores(self, Cmd):
self.__class__.Comando = Cmd
def EventoBotao(self):
self.InsereValores(100)
App = Aplicativo()
def Funcao1():
App.EventoBotao()
App.MostraValor()
def Funcao2():
App.MostraValor()
if __name__ == "__main__":
p1 = Process(target=Funcao1)
p2 = Process(target=Funcao2)
p1.start()
p2.start()
p1.join()
p2.join()