from multiprocessing import Process, Pipe def sender(conn): data = b"Hello, world!" conn.send_bytes(data) conn.close() def receiver(conn): data = conn.recv_bytes() print(data) conn.close() if __name__ == "__main__": parent_conn, child_conn = Pipe() p = Process(target=sender, args=(child_conn,)) q = Process(target=receiver, args=(parent_conn,)) p.start() q.start() p.join() q.join()
from multiprocessing import Process, Pipe def sender(conn): img_file = "image.jpg" with open(img_file, "rb") as f: img_data = f.read() conn.send_bytes(img_data) conn.close() def receiver(conn): img_data = conn.recv_bytes() with open("received_image.jpg", "wb") as f: f.write(img_data) conn.close() if __name__ == "__main__": parent_conn, child_conn = Pipe() p = Process(target=sender, args=(child_conn,)) q = Process(target=receiver, args=(parent_conn,)) p.start() q.start() p.join() q.join()In this example, the sender process reads an image file as bytes and sends it through the pipe to the receiver process, which saves it to a file. Both examples use the Python multiprocessing package.