Why doesn't this code execute the signal handler until after $sth->execute completes? And more importantly, how can I fix it?
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Sys::SigAction qw( set_sig_handler );
my $dbh = DBI->connect('dbi:Pg:dbname=dc');
eval {
my $h = set_sig_handler('ALRM', sub { die "timeout\n" });
eval {
alarm 1;
my $sth = $dbh->prepare("SELECT pg_sleep(10)");
print "Before execute\n";
$sth->execute;
print "After execute\n";
$sth->finish;
};
alarm 0;
die "$@" if $@;
};
die "$@" if $@;
print "Finished\n";