For example I have an Event class which looks like
class Event:
def __init__(self):
self.events = dict()
def on(self, name, callback):
self.events[name] = callback
def emit(self, name):
callback = self.events[name]
if callable(callback):
callback()
And when I try to use it in main thread it works.
if __name__ == "__main__":
event = Event()
event.on("hello", lambda: print("hello world"))
event.emit("hello") # OUTPUT: hello world
But when I try to register my event in another process it is not changed nowhere but same process. I have defined two functions, one of those sets new event and other emits that event. Then running those function on different processes.
def soldier(e):
e.on("hello", lambda: print("hello world"))
def officer(e):
e.emit("hello")
if __name__ == "__main__":
event = Event()
process1 = Process(target=officer, args=(event,))
process2 = Process(target=soldier, args=(event,))
process1.start()
process2.start()
process1.join()
process2.join()
The expected resul is the same as above example without processes but getting error as the first process changes the value of event.events only inside of it and the changed value is not visible outside of the process.
How to see the changed value of custom class object outside of the process?