JuliaLang/julia — pull request #7478 by vtjnash (2014-07-01 03:19:18+00:00)
Title: discontinue readavailable()

This is really hard function to use correctly, since the only correct usage of this function is in a stream reader:
```julia
buf = Uint8[]
while !eof(s)
bytes = readavailable(s)
append!(buf, s)
if enough(buf)
f(buf)
empty!(buf)
end
end
f(buf)
```

However, essentially all of the code I see posted to blogs and mailing lists to use this function are incorrectly defined, and subject to race conditions and the badly-defined behavior of this function (that and probably will stop working as soon as you try to bundle it into your application and output a decent amount of information, or forget that stdout is buffered, or run into a bit about latency)

I have seen users resort to it in the following situation, when users can't understand why `readall` hangs:
```julia
(outRead, outWrite) = redirect_stdout()

print("Test")
print("ing")

close(outWrite)

data = readavailable(outRead)

close(outRead)
```
(copied from: http://thenewphalls.wordpress.com/2014/03/21/capturing-output-in-julia/)

however, the answer to their quandary is simple: `outWrite` is only one of the handles to the stdout. until you call `redirect_stdout` again, julia still has a second handle open (on fd 2) for use by `c` functions

related: https://github.com/JuliaLang/julia/issues/7022