16 Apr '12, 9am

Setting $stdout per-thread via @zite

drbrain | Wed, 16 Aug 2006 18:58:00 GMT Posted in Hacking , Ruby cdfh on #ruby-lang asked how to redirect $stdout per-thread and I came up with this solution, redirect via a thread-local variable: ## # Allows $stdout to be set via Thread.current[:stdout] per thread. module ThreadOut ## # Writes to Thread.current[:stdout] instead of STDOUT if the thread local is # set. def self.write(stuff) if Thread.current[:stdout] then Thread.current[:stdout].write stuff else STDOUT.write stuff end end end $stdout = ThreadOut Simple test: require 'stringio' require 'threadout' s = StringIO.new Thread.start do Thread.current[:stdout] = s puts 'redirected to StringIO' end.join Thread.start do puts 'no redirection' end.join puts s.string Output: no redirection redirected to StringIO

Full article: http://blog.segment7.net/2006/08/16/setting-stdout-per-th...

Tweets

Ruby Setting $stdout per-thread $stdout vs STDO...

blog.segment7.net 16 Apr '12, 9am

drbrain | Thu, 17 Aug 2006 16:47:00 GMT Posted in Ruby You may have noticed me using both $stdout and STDOUT in my last po...

Nail Care chat thread! - Page 194 - PurseForum:...

forum.purseblog.com 16 Apr '12, 8am

Random question, cauz I couldn't find a thread for it and didn't know how to find a fitting name for a new one but beeing ...

5 short tips on setting your running goals for the new year #running

5 short tips on setting your running goals for ...

runaddicts.net 13 Apr '12, 3pm

Interested in writing for RunAddicts.net? Get started now! Every 1st of January brings some great New Year’s resolutions a...