On Fri, Jul 23, 2010 at 2:15 PM, Thomas Guettler <h...@tbz-pariv.de> wrote: > Hi, > > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource > temporarily unavailable) > on write(). My working code looks like this. But I am unsure how many bytes > have been written to the > pipe if I get an EAGAIN IOError. Up to now I retry with the same chunk. > > If I get EAGAIN can I just sleep, and then retry with the same data chunk? > > pipe=subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=-1) > fcntl.fcntl(pipe.stdin, fcntl.F_SETFL, os.O_NONBLOCK) > .... > chunk_size=1024 > while select.select([], [pipe.stdin], [], 5):
Please read the documentation of the select.select function. You are not using it correctly. After the call returns, you need to check whether the descriptor you are interested in is actually ready. If select reaches your timeout, it will simply return three empty lists, and your write will get EAGAIN. In general, after select has told you a descriptor is ready, the first write after that should always succeed. BTW, from the documentation of file objects, it seems write always wants to write the entire string you give it, since it does not return anything. In that case, you might want to get the descriptor for the file object (using pipe.fileno()) and use that for writing. > <snipped remaining code> -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list