Есть ли способ создать обратный вызов, который выполняется всякий раз, когда что-то отправляется в основной процесс от дочернего процесса, инициированного через multiprocessing
?Лучшее, что я могу себе представить, это:
import multiprocessing as mp
import threading
import time
class SomeProcess(mp.Process):
def run(self):
while True
time.sleep(1)
self.queue.put(time.time())
class ProcessListener(threading.Thread):
def run(self):
while True:
value = self.queue.get()
do_something(value)
if __name__ = '__main__':
queue = mp.Queue()
sp = SomeProcess()
sp.queue = queue
pl = ProcessListener()
pl.queue = queue
sp.start()
pl.start()