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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|