import multiprocessing def child(conn): message = conn.recv() print(f"Received message: {message}") conn.close() if __name__ == '__main__': parent_conn, child_conn = multiprocessing.Pipe() p = multiprocessing.Process(target=child, args=(child_conn,)) p.start() parent_conn.send("Hello from parent process!") parent_conn.close() p.join()
import multiprocessing def child(conn): while True: message = conn.recv() if message == 'DONE': break print(f"Received message: {message}") conn.close() if __name__ == '__main__': parent_conn, child_conn = multiprocessing.Pipe() p = multiprocessing.Process(target=child, args=(child_conn,)) p.start() parent_conn.send("Hello from parent process!") parent_conn.send("Another message from the parent") parent_conn.send("DONE") parent_conn.close() p.join()In both of these examples, the multiprocessing package was used.