Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: timing out or interrupting a mysql query

by clueless newbie (Chaplain)
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-06-25 12:41 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.