from multiprocessing import Pipe parent_conn, child_conn = Pipe() while True: if parent_conn.poll(): # Data is available to read data = parent_conn.recv() # Process the data else: # Wait for 1 second and try again sleep(1)
from multiprocessing import Process, Pipe import time def sender(conn): time.sleep(5) conn.send('Hello from sender') def receiver(conn): while True: if conn.poll(): msg = conn.recv() print(msg) if __name__ == '__main__': parent_conn, child_conn = Pipe() p1 = Process(target=sender, args=(parent_conn,)) p2 = Process(target=receiver, args=(child_conn,)) p1.start() p2.start()This code creates two processes- one for sending data and the other for receiving it. The Pipe connection is used to communicate between these processes. The `sender()` function sends a message to the Pipe connection after waiting for 5 seconds. The `receiver()` function polls the connection and prints the received message if any. The processes are started using the `Process` class and the `multiprocessing` package library is used for interprocess communication. In conclusion, Python multiprocessing Pipe poll is a useful method for checking whether data is available to be read from a Pipe connection. It is easy to use and can be used with the `multiprocessing` package library for interprocess communication.