On Thu, Aug 12, 2010 at 5:09 AM, Paul Harrington <xeno / badenoughdu.de> wrot=
e:
> Pen Ttt wrote:
>> probem1:
>> the following program can only run =A0in irb console,it can't run with
>> command :
>> ruby /home/test.rb,why?
>> require 'rubygems'
>> require 'net/http'
>> threads =3D []
>> open("/home/pt/test/data","a+") do |wfile|
>> str=3D%w(http://table.finance.yahoo.com/table.csv?s=3DIBM
>> http://table.finance.yahoo.com/table.csv?s=3DYHOO
>> http://table.finance.yahoo.com/table.csv?s=3DAACC)
>> for page_to_fetch in str
>> =A0 =A0Thread.new(page_to_fetch) do |url|
>> =A0 =A0 info =3D Net::HTTP.get_response(URI.parse(url)).body
>> =A0 =A0 puts info
>> =A0 =A0end
>> =A0end
>> 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 =3D str.map do
  Thread.new [...snip...]
end

threads.each {|t| t.join}

Jesus.