Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Trouble with timeout
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Luka Stolyarov  
View profile  
 More options May 30 2010, 6:27 pm
Newsgroups: comp.lang.ruby
From: Luka Stolyarov <luk...@gmail.com>
Date: Sun, 30 May 2010 17:27:48 -0500
Local: Sun, May 30 2010 6:27 pm
Subject: Trouble with timeout
Hi.  I have a small script that I use to download archives from the web.
The code looks like this:

require 'rubygems'
require 'mechanize'

def downloader()
  agent = WWW::Mechanize.new

  # create agent object
  page = agent.get('http://www.myurl.com')

  #authenticate
  form = page.forms.first
  form.username = '####'
  form.password = '####'

  #submit form
  page = agent.submit form

  #grab all links that have zip in them
  mylinks = page.links_with(:href => /zip\//)

  #for each link download and rename
  mylinks.each do |archive|

    name = archive.href.split('zip/')[1].sub('/','').strip

    puts "Archive #{name} is saving..."

    myfile = agent.click(archive)

    output = File.open("/Users/luka/Desktop/#{name}.zip", 'w') {|file|
file << myfile.body }

    puts "Done!"

  end
end

begin
  downloader
rescue Timeout::Error
  puts 'Timeout was detected.  Trying again...'
  downloader
end

However, I've been having problems with timeouts from time to time, so I
ended up making this code into a function and upon timeout invoke this
function once again, as you can see at the bottom of the code. However,
I still get an error, which looks like this on timeout:

Archive 914188 is saving...
Timeout was detected.  Trying again...
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tim eout.rb:60:in
`rbuf_fill': execution expired (Timeout::Error)

So it tries to rescue the timeout but obviously calling the same
function again is a bad idea.  I was wondering why is it, and what would
be a proper solution.
Thanks!

Luka
--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Walle Wallen  
View profile  
 More options Jun 1 2010, 10:50 am
Newsgroups: comp.lang.ruby
From: Walle Wallen <walle.st...@gmail.com>
Date: Tue, 1 Jun 2010 09:50:53 -0500
Local: Tues, Jun 1 2010 10:50 am
Subject: Re: Trouble with timeout
begin
  downloader
rescue Timeout::Error
   puts 'Timeout was detected.  Trying again...'
   retry
end
--
Posted via http://www.ruby-forum.com/.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luka Stolyarov  
View profile  
 More options Jun 1 2010, 12:25 pm
Newsgroups: comp.lang.ruby
From: Luka Stolyarov <luk...@gmail.com>
Date: Tue, 1 Jun 2010 11:25:15 -0500
Local: Tues, Jun 1 2010 12:25 pm
Subject: Re: Trouble with timeout

I'll try it out, thanks!

Walle Wallen wrote:
> begin
>   downloader
> rescue Timeout::Error
>    puts 'Timeout was detected.  Trying again...'
>    retry
> end

--
Posted via http://www.ruby-forum.com/.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »