-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
stream messages come in irregular chunks #342
Comments
I'm not an expert of the Jupyter protocol but this seems to be the correct behavior given |
Are you sure? Other kernels simply output an
As before, there is an initial message with a single value and then the other values. |
Do you have a full session? |
Using IJulia or other kernels? |
Whatever kernels.... |
Okay. Let me send you another session. |
The stream message type should be used for stdout according to this ? |
My understanding is that Also, since the output of |
Yes, I think you're right. The only difference is that IJulia produces one initial message containing a single value. That's what is weird but the stream type is okay. Would it be possible to fix that part? I'm not sure how many values are needed to require more than one message, though. By the way, there was a small interruption when typing input [5]. Anyway, this is the session:
|
My guess is that you want to send out the output as early as possible so that the user can see real time update from the program. I'll wait for others to comment on this though since I'm not 100% sure. |
Well, the idea is to have the kernels behaving the same as much as possible. There is a really small delay after receiving the first message with a single value (in this case, UPDATE: The delay is more noticeable when you increase the number of iterations. For example:
|
There are
|
I understand your first point. Obviously, it is not sensible to have many tiny stream messages. Unfortunately, for some reason that is exactly what we have. The first stream message is always tiny consisting of a single element. It would be much better to have a larger threshold to send stream messages. I don't think other kernels are waiting for all the messages in order to send a single huge stream message, but the partitioning of the messages is more uniform. I don't have a concrete example right now but there are hundreds of elements in each stream message in IPython. Definitely I'm not suggesting that |
I think the first message is small because the stdout thread has already been asleep for a while, so it wakes up the instant bytes are written. One solution might be to put the stdout task to sleep for 100ms just before executing a code cell. |
But I'm not sure what problem that would solve. Even if we sleep the stdout task, you cannot in general rely on output occurring within a single stream message. |
Not can you rely on the partitioning always being uniform. Why should you care? |
As I said, the first message produces a delay in showing the output. In the previous example, printing numbers in a loop, it looks like the first number is shown, then there is a small delay and finally the other numbers are received as usual. It gives the impression something is not as smooth as it should. If the output needs more than a single stream message, that's perfectly okay. The idea is not to have stream messages of exactly the same length. They only need to be reasonable in their length. |
What's not reasonable for the current version? It seems like a pretty good compromise between showing the results as the output are generated and not sending too many messages. |
Sending a single element in the first message causes a delay in the output. The first time I launched the notebook, I saw that delay immediately and thought this was due to something wrong with the installation, then when still happened I thought it was a thing of the language. Your reasoning is correct. If you want to have a compromise between responsiveness and not being wasteful in the number of messages sent, you wouldn't choose to send a single value in the first message and then 100 in the next one. |
Does anyone have a work-around for this -- perhaps some way to add in a slight pause between the execution of cells when running multiple cells at once? |
I'm afraid I can't really follow the discussion there, but calling
If this should be added in to IJulia I can't tell where. |
I think he meant |
I might have misunderstood, but running
produces the same results as above. |
Add a call to |
+1 for this, with the mixup of STDERR/OUT across multiple cells |
I think the following is related and more problematic as it leads to the loss of some output. I keep running into the problem that cells that produce a lot of output / take a long time to run have truncated output in the notebook. For instance there might be an exception and only the first two lines of the error are shown:
The backtrace does appear when the same code is run outside of the notebook. If there was another cell queued for execution, then the missing output sometimes appears in the output of that cell. If not, the missing output is lost. Note that I'm using the example of exceptions because it is the most annoying one (can't use the notebook for debugging), but it happens with all sorts of outputs, for instance printing a float number and getting "3" as the cell's output, with ".1415" appended to the next cell's output. |
I'm working on a fix for these and related IO problems. In the meantime, does adding a https://github.com/JuliaLang/IJulia.jl/blob/master/src/execute_request.jl#L224 work as temporary measure? (FYI: It's 0.11 just to be slightly longer than the |
Thanks for working on it!
Investigating further I find that if I wrap the call in try
run()
catch
@show Base.catch_backtrace()
end then |
Instead of sleeping during the read loop to throttle the number of stream messages sent, we now continually read the read_stdout and read_stderr streams (whose buffers are limited to 64KB on OSX/Linux, 4KB Windows?) and add data read into our own IOBuffers for STDOUT/STDERR. The rate of sending is now controlled by a stream_interval parameter; a stream message is now sent at most once every stream_interval seconds (currently 0.1). The exception to this is if the buffer has reached the size specified in max_size (currently 10KB), and will then be sent immediately. This is to avoid overly large stream messages being sent. Improves flush() so that it will have a very high chance of flushing data already written to stdout/stderr. The above changes fix JuliaLang#372 JuliaLang#342 JuliaLang#238 347 Adds timestamps to the debug logging and the task which the vprintln call is made from. Fixes using ?keyword (e.g. ?try)
Instead of sleeping during the read loop to throttle the number of stream messages sent, we now continually read the read_stdout and read_stderr streams (whose buffers are limited to 64KB on OSX/Linux, 4KB Windows?) and add data read into our own IOBuffers for STDOUT/STDERR. The rate of sending is now controlled by a stream_interval parameter; a stream message is now sent at most once every stream_interval seconds (currently 0.1). The exception to this is if the buffer has reached the size specified in max_size (currently 10KB), and will then be sent immediately. This is to avoid overly large stream messages being sent. Improves flush() so that it will have a very high chance of flushing data already written to stdout/stderr. The above changes fix JuliaLang#372 JuliaLang#342 JuliaLang#238 JuliaLang#347 Adds timestamps to the debug logging and the task which the vprintln call is made from. Fixes using ?keyword (e.g. ?try)
There is something unusual in the way IJulia is responding to the
whos()
command. Usually, in a fresh environment the output should be something like this:However, using the kernel directly, it outputs a couple of stream messages. The first message only shows one of the variables or modules in the environment and the second message outputs the rest. For example:
First message:
and the second:
This is the complete session:
I'm not sure why IJulia is using stream messages. As far as I know, other kernels (IPython, IR) are using
msg_type: execute_result
instead. Is this a bug?The text was updated successfully, but these errors were encountered: