> Somehow I have an idea that output to stderr will take effect immediately
> without any caching, maybe that comes from another language/platform.
In C stdout is buffered by default, stderr is not.
In Go neither os.Stdout nor os.Stderr is buffered.
If you pass os.Stderr to fmt.Fprintf, the output should appear
immediately. If you don't see this, you'll have to give us an
example.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.For more options, visit https://groups.google.com/groups/opt_out.
> But it turns out that the dots all show up at once when the lengthy processShow us the code.
> finished, not one by one during it.
Tell us how you are running it.
and I can think of a better example to proof it.
I was hoping for a smaller example that would be easy for us to try
ourselves to see if we can replicate the behaviour.
Tell us how you are running it.
Run under Win7 DOS, tried both "go run" and run the compiled .exe file. The behavior is the same, dots all show up at once.
What I can't explain is that, I tried Péter's example, also run under Win7 DOS, tried both "go run" and run the compiled .exe file, and for this case, I can see the dots progressing. I don't know if there is another file writing process in my loop is the cause of the behavior difference, and I can't think of a better example to proof it.
env GOMAXPROCS=10 ./$YOURBIN> My latest theory is that the tight loop in my code "starves" go from
> processing "fmt.Fprintf(os.Stderr, ".")", while time.Sleep will enable go to
> take a breath and do the output.
>
> Anyone can write a PIE Calculator in GO and do "fmt.Fprintf(os.Stderr, ".")"
> every so often to test the point?
>
should be sufficient to test that hypothesis.
On Wed, Oct 16, 2013 at 2:10 PM, Tong Sun <sunto...@gmail.com> wrote:Well, what about my example?
>
>> I was hoping for a smaller example that would be easy for us to try
>> ourselves to see if we can replicate the behaviour.
>
>
> As said before, I can't think of a better example to show it.
I took a closer look at your program. It seems to do various database
operations. I don't know how long those would take. Then it writes
out a file, and that is where you are printing the dots. Writing the
file should be fast. It's just a local file and the printing should
be fast. The only potentially slow operation I see in that loop is
row.MustGet; I don't know what that is.
Is it possible that your program just runs so fast at the point of
printing the dots that they all appear at once?
This is what your program outputs:...............................Finished correctlyIs this wrong?
But it turns out that the dots all show up at once when the lengthy process finished, not one by one during it.... I run under Win7 DOS, tried both "go run" and run the compiled .exe file. The behavior is the same, dots all show up at once. My program runs in minutes. I watched closely, and they were all "nothing" then all-of-sudden "everything".I also tried Péter's example, http://play.golang.org/p/ENdvg6u37m, also run under Win7 DOS, tried both "go run" and run the compiled .exe file, and for this case, I can see the dots progressing.
In Go neither os.Stdout nor os.Stderr is buffered.
> Then we should see the dots progressing. ...I don't see why the should behave as you've described.
Anyway to flush the os.Stderr?
Why? Ian just said that neither is buffered,.The two run identically in your example.
I think Ian's theory that it's completing quickly is probably right, else Windows behaves differently.
I did. I run your http://play.golang.org/p/HX0G79dvV9 program against BigTable, instead of sys.databases.
> ... Then we should see the dots progressing. However, you will find, in this simple example, the dots all show up at once after the lengthy process finished, not one by one during it. I.e., "nothing" then all-of-sudden "everything". ...
Yes, I see all dots are printed at once. But why shouldn't they? Please explain.
And whatever reason it happens, it is not because of "os.Stderr is buffered". I think that "os.Stderr is buffered" is red herring here. I would look for a different explanation instead.
Agree. but the above result, observing from an end user prospective, shows the symptom of Stderr being buffered to the end, which was my initial guess. And if you have following the entire thread, you would know that I was trying to come up with all different explanations and have written small code to test whether they are correct or not. Just so far all my other guessings have been proving wrong.That's so much I can do from an end user prospective, trying to guess what's happening in the black box.