Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: timing out or interrupting a mysql query

by clueless newbie (Hermit)
on Feb 02, 2011 at 15:52 UTC ( #885772=note: print w/replies, xml ) Need Help??

in reply to timing out or interrupting a mysql query

The part relevant to implementing timing out and interrupting a mysql query can be condensed to:

use strict; ... use warnings; use DBI; use Sys::SigAction; ... my $sth_o=$dbh_o->prepare($SQL_s); my $rows_s; eval { # Time out and interrupt work my $TimeOut=Sys::SigAction::set_sig_handler('ALRM',sub { $dbh_o->clone()->do("KILL QUERY ".$dbh_o->{"mysql_thre +ad_id"}); die "Timed Out!"; }); local $SIG{INT}=sub { $dbh_o->clone()->do("KILL QUERY ".$dbh_o->{"mysql_thre +ad_id"}); die "Ctrl-C'd!"; }; # Set alarm alarm(<max time allowed>); $rows_s=$sth_o->execute(@Argument_a); # Clear alarm alarm(0); }; # Prevent race condition alarm(0); die if $@;

My attempts to use a local $SIG{ALRM} in place of the Sys::SigAction::set_sig_handler weren't successful. I'll freely admit to not trying too hard as Sys::SigAction::set_sig_handler works fine.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885772]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2016-10-25 22:22 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.