Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python non blocking recv with pipe between processes?

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?

like image 878
AturSams Avatar asked Nov 27 '25 10:11

AturSams


1 Answers

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

like image 126
Sriram Gopalakrishnan Avatar answered Nov 30 '25 00:11

Sriram Gopalakrishnan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!