From: ahoward Date: 2003-02-27T00:15:37+09:00 Subject: Re: Ruby in Performance Testing On Wed, 26 Feb 2003, E F van de Laar wrote: > I also get "Bad file descriptor" errors at times. > #!/usr/bin/ruby -w > > require 'socket' > require 'thread' > > threads = [] > > (1..500).each do |c| > threads << Thread.new(c) do |client| > (1..10).each do |request| > begin > TCPSocket::open('localhost', 80) { |s| > # perform some socket reading writing here > # and print some output ^^^^^^^^^^^^^^^^^ > } > rescue Exception => e > $stderr.puts e ^^^^^^^^^^^^^^ > end > end > end > end > > threads.each { |t| > t.join > } i'm not sure, but accessing stdout/stderr from this many threads at once may be a problem - i've had problems with it before. one thing i've done in my threaded problems is something like this : #!/usr/bin/env ruby require 'thread' tds = [] toutput = [] sem = Mutex.new 4.times do |tid| toutput[tid] = [] tds << Thread.new (tid) do 2.times do |i| Thread.pass while not sem.try_lock toutput[tid] << "msg #{i} from thread #{tid}..." sem.unlock end end end toutput.each do |msgs| msgs.each do |msg| puts msg end puts end which would output : msg 0 from thread 0... msg 1 from thread 0... msg 0 from thread 1... msg 1 from thread 1... msg 0 from thread 2... msg 1 from thread 2... msg 0 from thread 3... msg 1 from thread 3... this technique alone has helped my concurrent programming skiils since i can read the bloody output! -a > > Emiel > -- > E F van de Laar > +31648183479 > www.il.fontys.nl/~emiel > > -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================