代码之家  ›  专栏  ›  技术社区  ›  Michael

路缘没有反应

  •  1
  • Michael  · 技术社区  · 10 年前

    我用Feedjira解析RSS流。 当我使用 fetch_and_parse 方法有时会被阻塞,没有反应。

    手动抑制下载也会发生同样的情况。

    我在循环中写道:

    @my_logger.info "--- Before perform ---"
    easy = Curl::Easy.new
    easy.follow_location = true
    easy.max_redirects = 3 
    easy.connect_timeout = 120
    easy.url = url
    easy.useragent = "Ruby/Curb"
    easy.perform
    @my_logger.info "--- After perform ---"
    doc = easy.body_str
    easy.close
    

    一段时间后(可能是一天或一小时),进程在 easy.perform 行,没有响应。E、 g.过程输出 --- Before perform --- 没有别的。

    1 回复  |  直到 10 年前
        1
  •  2
  •   javiyu    10 年前

    它可能与随机发生的网络问题有关。

    如果使用超时,则可以在长时间运行的任务中跳过这种情况。

    require 'timeout'
    begin
      Timeout.timeout(5) do      
        easy.perform
      end
    rescue Timeout::Error
      puts 'timeout'
    end