0

I'm trying to work with pipes on Python 3.3/Linux as of https://stackoverflow.com/a/6193800/2375044, but if I use the following, program "hangs":

import os
readEnd, writeEnd = os.pipe()
readFile = os.fdopen(readEnd)
firstLine = readFile.readline()

Changing os.fdopen(readEnd) to os.fdopen(readEnd, 'r+') I get

io.UnsupportedOperation: File or stream is not seekable.

I need a readline() function over the pipe, but I don't know what else to do.

Community
  • 1
  • 1
Siot
  • 95
  • 1
  • 6
  • 2
    Why are you using mode "r+"? That's only for reading *and writing*, and pipes are unidirectional: you can't write on the read end. (And "r" mode is not related to the apparent hang; I can't be sure, but I suspect it's due to the program you're piping-to doing more buffering than you expect.) – torek Nov 08 '13 at 11:52
  • @torek sorry, I'm unable to locate a reference where I read something about this :( – Siot Nov 08 '13 at 12:11
  • 1
    in [the original question](http://stackoverflow.com/q/6193779/4279) between the `os.pipe()` call and the `.readline()` call there is a comment: `# something somewhere writes to the pipe` It must be replaced by [the code that writes something to the `writeEnd`](https://gist.github.com/00bada6113a5b573ed47). – jfs Nov 08 '13 at 12:40
  • 3
    @J.F.Sebastian is correct. readFile.readline() is a blocking operation that is waiting for input. Since there is nothing in the PIPE buffer it will never complete until something is written to it. – Necrolyte2 Nov 08 '13 at 12:42
  • @J.F. omg! I was not seeing the forest. Thanks – Siot Nov 08 '13 at 12:48

0 Answers0