From: jason joo Date: 2010-08-12T13:41:07+09:00 Subject: Re: Multithreading problem --000e0cd3317e70d451048d98f92d Content-Type: text/plain; charset=ISO-8859-1 u forgot to add it to ur thread list array "threads[]" after u created a thread. so the array "threads[]" left empty and u joined nothing in the end then these threads were terminated because the main thread was terminated and u got nothing in that file 2010/8/12 Pen Ttt > 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 > problem2: > i want to write output into my file,just change "puts info" into > "wfile.puts info",it can not run. > 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 > wfile.puts info > end > end > threads.each {|thr| thr.join} > end > -- > Posted via http://www.ruby-forum.com/. > > --000e0cd3317e70d451048d98f92d--