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

Re: timing out or interrupting a mysql query

by clueless newbie (Friar)
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.


Comment on Re: timing out or interrupting a mysql query
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-09-23 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls