Code like below used to help me to cope with timeouts for blocking IO on Windows. Of course introducing threads may be undesirable or totally unusable for your purposes, i.e. not sure if it's worth anything.
use strict; use warnings; use threads; use threads::shared; my $err :shared = ''; sub timed_action (&$;@) { my ( $code, $timeout, @args ) = @_; local $SIG{ TERM } = sub { threads-> exit }; lock( $err = '' ); my $t = async { { lock $err } my $result = eval { $code-> ( @args )}; lock( $err = $@ ); cond_signal $err; return $result }; if ( !cond_timedwait $err, time + $timeout ) { $err = 'Timeout!!!'; $t-> kill( 'TERM' ); } if ( $err ) { print "$err\n"; $t-> detach; return undef } return $t-> join; } # let's test it use LWP::Simple; timed_action { get 'http://10.255.255.1' or die } 3;
In reply to Re: Timeout Failing
by vr
in thread Timeout Failing
by beckmanel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |