Ruby:此段代码中OpenURI中的open函数为什么没有执行
ringa_lee
ringa_lee 2017-04-22 08:56:00
0
1
784
#encoding:utf-8
require 'net/http'
require 'thread'
require 'open-uri'

queue = Queue.new
threads = []
def get_html(url)
  open(url) do |f|
    #为什么没有执行到这边呢?
    puts f.read
  end
end

#add work to the  queue
queue<<"http://www.cnblogs.com"
10.times do
  threads<<Thread.new do
    until queue.empty?
      work_unit = queue.pop(true) rescue nil
      if work_unit
        puts get_html(work_unit)
      end
    end
  end
end


ringa_lee
ringa_lee

ringa_lee

全部回覆(1)
黄舟

解決方法:
在末尾加上

threads.each{|t| t.join}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!