3
我正在从(降序)时间有序库中下载图像。我想停下来,当我们看到已经停下来的照片时。从线程循环中突破
require 'thread/pool'
def getimg(uri)
#...
if File.exist? filename
raise "Already done." # something like this
end
#...
end
pool = Thread.pool(4)
thumbs.each do |a|
pool.process {
getimg(URI(a.attr('href')))
}
end
这听起来不错,但似乎并不奏效。我试过修剪!太。 – Kambus 2014-08-30 14:17:36
@Kambus,我尝试了这一点,它按预期工作。这是我的实验:http://pastebin.com/fgSw6BZT – falsetru 2014-08-30 14:19:03
嗯,这很奇怪!我必须在File.exist之前获得一个页面才能知道文件名,并且不管pool.shutdown如何都会运行。尝试在文件检查之前添加pri:http://pastebin.com/i7mb3PXQ – Kambus 2014-08-30 14:47:19