Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

This morning Twitter had a DoS attack, which also brought the site I'm working on to a crawl. I was wondering if there would be a way to time out my eval statement apart of Net::Twitter so that I can continue to display the page if no results are brought back within a few seconds. Here is my eval code:
#Parameters: id, user_id, screen_name, since_id, max_id, count, page eval { my $statuses = $nt->user_timeline({ screen_name => 'username', count + => 4 }); for my $status ( @$statuses ) { my $message = substr $status->{text}, 0, 70; if ($status->{text} ne $message) { $message = $message . '...'; } print $message; } }; if ( $@ ) { if ( blessed $@ && $@->isa('Net::Twitter::Error') ) { #... use the thrown error obj warn $@->error; } else { # something bad happened! warn "Twitter is failing!"; } }
I want to try and timeout after like 3 seconds.

Thanks for your help monks!

Replies are listed 'Best First'.
Re: Time Out eval
by Herkum (Parson) on Aug 06, 2009 at 18:24 UTC

    Have you taken a look at the alarm() function? I think that will do what you need however I have not used it before.

Re: Time Out eval
by bot403 (Beadle) on Aug 06, 2009 at 18:25 UTC
      I'm pretty sure the ukranian website there isn't hosting approved copies of the Perl bookshelf, though I could be mistaken.