On 05/27/2011 09:34 AM, BG - Ben Armstrong wrote:
Apparently, synchronous output to stdout in JRuby is implemented differently from MRI. It appears to flush after each "print" whereas in MRI it does not. Can this behaviour be modified?This sample code, demonstrates the lack of a flush after each print in MRI, even though $stdout.sync=true : $ ruby -e "3.times {|i| print i+1; sleep 1}" I see "123" printed all at once after a 3-second sleep, so clearly there was no flush after each print. JRuby, too, has $sdtout.sync=true, but when I run the same sample code, there is a flush after each print, as I see each number printed, one at a time, with a one second sleep between.
Guh. This part of my analysis is incorrect. I had output the value of $stdout.sync in irb for both implementations, which of course sets things differently.
So in fact what I have found, using "jruby -e 'p $stdout.sync'" is that in MRI (1.8.7, 1.9.1 and 1.9.2) $stdout.sync=false, whereas in JRuby (1.6.0) $stdout.sync=true explaining the difference in behaviour quite tidily.
What this *doesn't* explain is why JRuby diverges from MRI here, nor does it suggest a way I can fix it. I've tried simply setting $stdout.sync=false, but then I end up with any interleaved $stdout & $stderr output coming out in the wrong order, so that's not really a viable workaround.
Ben --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
