From: LAMBEAU Bernard Date: 2010-08-27T19:16:12+09:00 Subject: Re: error handling with exceptions in multi-thread download --0016363b86845de74f048ecb67a4 Content-Type: text/plain; charset=ISO-8859-1 You probably have a TimeOut error. And the errors actually comes from: rescue Timeout::Error => e puts "#{web} failed" because web is not defined there. B On Fri, Aug 27, 2010 at 11:58 AM, Pen Ttt wrote: > > there are three program fragments,all of them have same problems, > all of them can run ,but when i downloaded 30% data,an error > ocurr > undefined local variable or method `web' for Data:Class (NameError) > cthreaddown is an array which contains many web. > would you kind to tell me how to fix it? > p1 > [code] > for page_to_fetch in cthreaddown > threads< datafile="/home/pt/stock/" > open(datafile,'a+'){|refile| > open(web){|webfile| > refile.puts webfile.read > puts "#{web} is over" > }} > end > end > threads.each {|thr| > begin > thr.join > rescue Timeout::Error => e > puts "#{web} failed" > rescue NameError => e > puts "#{web} failed" > rescue => e > puts "#{web} failed" > end > } > [/code] > p2 > [code] > for page_to_fetch in cthreaddown > threads< datafile="/home/pt/stock/" > open(datafile,'a+'){|refile| > begin > open(web){|webfile| > refile.puts webfile.read > puts "#{web} is over" > }} > rescue NameError => e > puts "#{web} failed" > rescue => e > puts "#{web} wrong" > end > end > end > threads.each {|thr| thr.join } > [/code] > > p3 > [code] > for page_to_fetch in cthreaddown > threads< datafile="/home/pt/stock/" > open(datafile,'a+'){|refile| > begin > open(web){|webfile| > refile.puts webfile.read > puts "#{web} is over" > }} > rescue NameError => e > puts "#{web} failed" > rescue => e > puts "#{web} wrong" > end > end > end > threads.each {|thr| > begin > thr.join > rescue Timeout::Error => e > puts "#{web} failed" > rescue NameError => e > puts "#{web} failed" > rescue => e > puts "#{web} failed" > end > } > -- > Posted via http://www.ruby-forum.com/. > > --0016363b86845de74f048ecb67a4--