From: "Jesús Gabriel y Galán" Date: 2010-08-12T16:26:23+09:00 Subject: Re: Multithreading problem On Thu, Aug 12, 2010 at 5:09 AM, Paul Harrington wrote: > Pen Ttt wrote: >> probem1: >> the following program can only run  in irb console,it can't run with >> command : >> ruby /home/test.rb,why? >> require 'rubygems' >> require 'net/http' >> threads = [] >> open("/home/pt/test/data","a+") do |wfile| >> str=%w(http://table.finance.yahoo.com/table.csv?s=IBM >> http://table.finance.yahoo.com/table.csv?s=YHOO >> http://table.finance.yahoo.com/table.csv?s=AACC) >> for page_to_fetch in str >>    Thread.new(page_to_fetch) do |url| >>     info = Net::HTTP.get_response(URI.parse(url)).body >>     puts info >>    end >>  end >> threads.each {|thr| thr.join} >> end > > threads is still an empty array. Try adding each thread to threads as > you create it. An idiom I usually use is this: threads = str.map do Thread.new [...snip...] end threads.each {|t| t.join} Jesus.