开发者

curl.perform throws invalid easy handle error under multi-threading env

I use curl of ruby gem curb to fetch multi urls under multi-threading env, but it throws "Invalid easy handle" exception, but if it runs one by one in single-threading env everything is ok.

module Http
  @@curl = Curl::Easy.new
  @@curl.timeout = 10 #second
  @@curl.follow_location = true
  @@curl.max_redirects = 3
  @@options = Ro开发者_如何学Gobot::HttpOptions.new

  def self.fetch(url, options=@@options, type=Robot::Type::HTML)
    @@curl.url = URI.unescape(url)==url ? URI.escape(url) : url
    @@curl.headers["User-Agent"] = options.user_agent
    begin
      @@curl.perform
    rescue Curl::Err::CurlError
      raise
    end
  end
end

self.fetch is called in multi-threading env.

Can someone help me on the thing? Thank you.


From the cURL documentation:

You must never share the same handle in multiple threads.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜