[英]What can I do about Mechanize waiting on an unresponsive web site?
有幾種方法可以解決它。
Open-Uri和Net :: HTTP都有傳遞超時值的方法,然后告訴底層網絡堆棧你願意等多久。 例如,Mechanize允許您在初始化實例時獲取其設置,例如:
mech = Mechanize.new { |agent|
agent.open_timeout = 5
agent.read_timeout = 5
}
這一切都在new
文檔中,但您必須查看源代碼以查看可以獲得的實例變量。
或者你可以使用Ruby的timeout
模塊:
require 'timeout'
status = Timeout::timeout(5) {
# Something that should be interrupted if it takes too much time...
}
http://mechanize.rubyforge.org/mechanize/Mechanize.html此頁面上有2個無證屬性open_timeout
和read_timeout
,請嘗試使用它們。
agent = Mechanize.new { |a| a.log = Logger.new("mech.log") }
agent.keep_alive=false
agent.open_timeout=15
agent.read_timeout=15
HTH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.