How to subscribe to an event from a process and to address specifically the data process in python 3?

Welcome! Decided to learn Python. Tell me how to subscribe to an event data change in the process?

I tried something like this:
import multiprocessing as mp
import logging
import time

def foo(q):
 i = 1
 while True:
 q.put({'yndx': i})
time.sleep(1)
 i += 1

if __name__ == '__main__':
mp.log_to_stderr().setLevel(logging.DEBUG)
mp.set_start_method('spawn')
 q = mp.Queue()
 p = mp.Process(target=foo, args=(q,))
p.start()
 while True:
 if not q.empty():
 broadcast = q.get()
 print(broadcast)


But then the infinite loop seems useful to the maximum and when they will be a lot of... time.sleep in an infinite loop to use do not want, as you want instant delivery of data.

And in the end the task is that one process receives data, and other processes processors take what they want. However, their number varies during the life of the program.
5e9ae058a0664391499429.png
April 19th 20 at 12:41
1 answer
April 19th 20 at 12:43
Solution
Figured out myself. To receive the event that there is new data use multiprocessing.Event()and for the exchange of data multiprocessing.Manager().dict()

Find more questions by tags multithreadingPython