Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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]
[erix]: I think it depends on the server
[erix]: hmm...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-11-18 21:40 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (278 votes). Check out past polls.