Answer the question
In order to leave comments, you need to log in
How to subscribe to an event from a process and address data to a specific process in python 3?
Greetings! Decided to learn Python. Can you tell me how to properly subscribe to the data change event in the process?
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)
Answer the question
In order to leave comments, you need to log in
Figured it out myself. To receive an event that there is new data, I use multiprocessing.Event()
, and to exchange datamultiprocessing.Manager().dict()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question