In article <[EMAIL PROTECTED]>, Brad Murdoch <[EMAIL PROTECTED]> wrote:
> im trying to run the select.selct() on a unix pipe, my expectation is > that it will block untill there is something there to read, then > continue. It seems to do this untill the pipe is written to once, then i > get a busy while loop. > shouldnt this stop each time, to wait for something to be written to > the pipe. obviously im a novice when it comes to python programming, > what am i missing here. > try: > fifo = open('test.fifo','r') > while 1: > line = False > r,w,x = select.select([fifo],[],[]) > if r: > line=fifo.read() > print line Well, two things, neither of them really unique to Python. The immediate problem is the semantics of pipe I/O, specifically "end of file." For pipes and other IPC devices, end of file means that the the other end of the file has been closed, which your "the pipe is written to" event probably does. >From this point on, read(2) returns 0 bytes, which means end of file. If you want to go back and do this again, you need to re-open the pipe. The second problem will bite you as soon as you get the first part working: fifo.read() is going to block until the pipe closes. If you switch to fifo.readline(), select may start failing to detect data that readline() buffers. For more reliable I/O in conjunction with select(), use POSIX I/O: fifd = os.open('test.fifo', os.O_RDONLY) ... while 1: ... data = os.read(fifd, 8192) Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list