Ruby Net::HTTP time out

前端 未结 2 1663
灰色年华
灰色年华 2020-12-09 17:09

I\'m trying to write my first Ruby program, but have a problem. The code has to download 32 MP3 files over HTTP. It actually downloads a few, then times-out.

I tried

2条回答
  •  悲哀的现实
    2020-12-09 17:46

    For Ruby 1.8 I used this to solve my time-out issues. Extending the Net::HTTP class in my code and re-initialized with default parameters including an initialization of my own read_timeout should keep things sane I think.

    require 'net/http'
    
    # Lengthen timeout in Net::HTTP
    module Net
        class HTTP
            alias old_initialize initialize
    
            def initialize(*args)
                old_initialize(*args)
                @read_timeout = 5*60     # 5 minutes
            end
        end
    end
    

提交回复
热议问题