-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
discontinue readavailable() #7478
Conversation
(@vtjnash did you intend to pull in helpdb changes?) |
(yes, i'm not sure why it is so big though, apparently it wanted to insert a lot of blank lines?) |
@@ -391,10 +391,10 @@ function _uv_hook_readcb(stream::AsyncStream, nread::Int, base::Ptr{Void}, len:: | |||
else | |||
if isa(stream,TTY) | |||
stream.status = StatusEOF | |||
notify(stream.closenotify) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a separate bugfix for the readall
function, which needs to be committed separately if Jeff refuses to merge this pull request
+1 If you have a separate bugfix, it belongs on master, ideally with a test case, not bundled with whatever PR you are working on. That is simply sound development practice, and has nothing to do with my willingness to merge PRs. Coupling the decision to fix a bug to the decision to deprecate some other function is insane. Separating them also allows others to selectively revert or run bisect more effectively. You seem to have one of the unlucky versions of sphinx that inserts extra unwanted newlines. In that case, please don't regenerate the helpdb. Somebody else can do it. |
@@ -473,3 +473,12 @@ scale!{T<:Base.LinAlg.BlasReal}(X::Array{T}, s::Complex) = error("scale!: Cannot | |||
|
|||
@deprecate which(f::Callable, args...) @which f(args...) | |||
@deprecate rmdir rm | |||
|
|||
function readavailable(this::AsyncStream) | |||
depwarn("readavailable() is discontinued, because users tend to mistakenly assume it will read everything that has been written. better defined alteratives include: readall(), readbytes(), nb_available(), and !eof()", :readavailable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is a bit too passive-aggressive. Needs a rewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
"readavailable is discontinued. please choose from the alternative I/O functions, such as readall(), readbytes(), nb_available(), and !eof(), depending on your intended usage"
the fixes to the test files revealed the bug in |
Let me repeat: whether the bug fix is a separate change is unrelated to whether I merge this PR. |
The modified repl test passes for me on master, without the readcb change. |
The repl test might pass, but it is dependent upon order-of-execution. Since we want to consider |
Isn't the |
what is there to notify? other streams don't have a EOF event, and they will eventually get a close event after the stream is closed |
Ah yes, I see there is a |
yes. that's a bit of a hack, because wait can't wait on multiple Conditions (hint, hint) |
Are you aware of any stream readers/parsers other than HttpParser, in Julia? I guess this is probably not a common enough task to warrant a (confusing) function in Base. Considering that people are apparently using |
Does it work to read fixed-size chunks and then look for short reads to detect end of stream? |
We use readavailable as a stream reader in IJulia. I'm not sure what @vtjnash is proposing as an alternative here. I suppose we could block on reading one byte, and then call |
I would use: Or maybe, takebuf_array? This formulation also avoids the busy-wait lockup if s is ever closed that exists in the current code. |
@vtjnash, that seems like it will be a spinloop (since (The stream is never closed in IJulia until the process completes, so that's not an issue.) |
I'll repeat my question:
|
@JeffBezanson, no, it doesn't work to read fixed-size chunks, unless the chunk size is 1 byte (which is too small to be efficient). Say I am reading chunks of 100 bytes, and the user prints 99 bytes to stdout. They will be waiting a long time for their output to show up in IJulia, because the I/O thread will be blocked until another byte is written. |
eof blocks until it can determine if you have data, or eof. If you had wanted to do fixed size reads, you could combine the eof test with wait_nb |
How do people usually do this? I'm guessing maybe Anyway, since a couple packages seem pretty happy with this function I lean towards moving this change out of 0.3. |
HttpParser really shouldn't use line buffering. Besides potential performance problems, some requests don't have new lines at the end. |
Yes, line buffering would only work for stdout in IJulia. libuv works by invoking a callback and telling you how many bytes it has. |
You can use |
Yes, but for printing text to stdout people are somewhat used to line buffering. Anyway removing this function is not a huge advantage so I'm moving this issue to 0.4. |
I don't think it's acceptable to delay output until a newline occurs in IJulia. However, if Still, I tend to agree that this should be a 0.4 change. |
|
I should also probably point out that since |
It should probably return a byte array anyway.
|
6c7c7e3
to
1a4c02f
Compare
We will keep this function but it should return a byte array instead of a string. |
This is really hard function to use correctly, since the only correct usage of this function is in a stream reader:
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:(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 callredirect_stdout
again, julia still has a second handle open (on fd 2) for use byc
functionsrelated: #7022