WWW::Mechanize::Timed https timeout does not work

℡╲_俬逩灬. 提交于 2019-12-04 13:31:56
Jude_Quintana

The below helped to set an alarm for each get(), Seems much easier than try-catch with sig alarm unless i'm missing something?

use Sys::SigAction qw(timeout_call);

if ( timeout_call( 60 ,sub { $ua->get('https://secured.site.com'); } ))
   {
print "ALARM page timed out after 60 seconds!\n" ;
exit;
}

Pretty much the same answer as this question but with actual code Ways to do timeouts in Perl?

text from http://metacpan.org/pod/Sys::SigAction

timeout_call()

$timeout ,$coderef

Given a code reference, and a timeout value (in seconds), timeout() will (in an eval) setup a signal handler for SIGALRM (which will die), set an alarm clock, and execute the code reference. $time (seconds) may be expressed as a floating point number.

If Time::HiRes is present and useable, timeout_call() can be used with a timer resolution of 0.000001 seconds. If Time:HiRes is not available then factional second values less than 1.0 are tranparently converted to 1.

If the alarm goes off the code will be interrupted. The alarm is canceled if the code returns before the alarm is fired. The routine returns true if the code being executed timed out. (was interrupted). Exceptions thrown by the code executed are propagated out.

The original signal handler is restored, prior to returning to the caller.

If HiRes is not loadable, Sys::SigAction will do the right thing and convert

one last thing to consider/keep in mind:

use of Sys::SigAction::timeout_call unsafe?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!