Reputation: 7952
Seen this line of code but could not find documentation
self.conn.setblocking(0)
The question is, how do you poll a pool of pipes without blocking? Got a parent process that needs to communicate with some unstable child processes and wish to poll and check periodically if they've something to say. Do not wish to block if they decide they need more time before they have something new to say. Will this magically do this?
Upvotes: 3
Views: 6105
Reputation: 11
you can check p.poll(0) then if the result was True then the pipe is not empty and you can receive the data without blocking .
Upvotes: 1
Reputation: 168
Creating a pipe will return two connection objects. A connection object offers the polling functionality, where you can check if there is anything to read. Polling functionality allows you to specify a timeout to wait for.
If you have a group of connection objects that you are waiting on, then you can use multiprocessing.connection.wait(), or the non-multiprocessing version of it.
For details , see https://docs.python.org/3/library/multiprocessing.html#multiprocessing.connection.Connection which will show you the connection object details. Look at the poll function
Upvotes: 3
Reputation: 8213
This is most likely what you were looking at: https://docs.python.org/2/library/socket.html#socket.socket.setblocking
You don't give much detail so I'm not exactly sure what you are trying to do, but usually when you have a number of sockets that you want to poll, you will use select (see these examples from PyMOTW).
Upvotes: 2