P
Pen Ttt
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
p2
p3
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<<Thread.new(page_to_fetch) do |web|
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:
for page_to_fetch in cthreaddown
threads<<Thread.new(page_to_fetch) do |web|
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 }
p3
Code:
for page_to_fetch in cthreaddown
threads<<Thread.new(page_to_fetch) do |web|
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
}