pythonmultiprocessingpipe

python multiprocessing pipe poll bug


Using pipes for process communication with the multiprocessing library I noticed some strange behaviour of the poll function. If I close the other end of the pipe poll() returns true which is kind of odd. The python docs dont really tell what to expect. Still I was thinking poll() would at least return false if there is definitely nothing in the pipe and the other end is even closed. I use python3.3.2 but it seems to be the same for python 2.7.5. Is this intended or a bug and if it´s not a bug what is it good for?

import multiprocessing

if __name__ == '__main__':

    con = multiprocessing.Pipe(True)
    con1, con2 = con

    print(str(con1.poll())) #prints False
    con2.close()
    con1.close()   

    con = multiprocessing.Pipe(True)
    con1, con2 = con

    con2.close()
    print(str(con1.poll())) #prints True
    con1.close()

Solution

  • I don't think this is a bug. I agree, the documentation is not clear in this respect, but there are several reasons why this behavior should be expected, and the opposite would cause more harm than good:

    Also note that there would be no good means of detecting that the other end closed, if poll returned False.