0

I have two process. in the future one should control a websocket the other thread receives messages from a funk module.

Now i want to have a callback on_message, that i can send something via NRF.

So i made a abstract experiment. but i cant find a away to call callbacks from another process.

import multiprocessing
from multiprocessing import Queue, Process

def main():
    main_queue = Queue()
    slave_queue = Queue()
    main_process = multiprocessing.Process(target=Main, args=(slave_queue, main_queue))
    slave_process = multiprocessing.Process(target=SlaveThread, args=(main_queue, slave_queue))

    main_process.start()
    slave_process.start()
    main_process.join()
    slave_process.join()


class SlaveThread:
    def __init__(self, main_queue, slave_queue):
        main_queue.put(self.callback)
        while True:
            slave_queue.get()()

    def print_slave_thread(self):
        print("SlaveThread")

    def callback(self):
        print("callback from Slave")


 class Main:
    def __init__(self,  main_queue, slave_queue):
       slave_queue.put(self.callback)
       while True:
            main_queue.get()()

    def print_what_websocket_has_send(self):
       print("MainThread")

    def callback(self):
       print("callback from Main")


if __name__ == '__main__':
    main()

sadly, this approach doesn't work.

Ipad
  • 393
  • 1
  • 6
  • 22

1 Answers1

0

I'm not sure if you can send functions to a multiprocess. You can, however, send information into a Queue which is then read from by your subprocess. You could send it a dict and then expand it into **kwargs if that was something necessary.

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290