http://www.perlmonks.org?node_id=671984

Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello esteemed code fellows

I just can't make it work. When I comment out the 'sleep' call, it works, though - this proves the alarm is working.

But the alarm doesn't bother at all. The query always takes about 2 or 3 seconds, according to the cronometer I've set up. How come?

Here we go:

local our $dbh = DBI->connect ("DBI:mysql:database=$db:host=$mysqlhost +","user","pass") || die "Can't connect to database: $DBI::errst +r\n"; $dbh->{RaiseError} = 1; local our $sth = $dbh->prepare ( "SELECT this from that;"); # Start of cronometer local our $t0; local our $t1; local our $elapsed; $t0 = gettimeofday; ######################### # Start of timeout ##### eval { local $SIG{ALRM} = sub { die "Sorry, time's up.\n" }; alarm 1; # some operation that might take a long time to complete ######################### ######################### $sth->execute( ); # sleep 3; ######################### alarm 0; }; die $@ if $@; ######################### # End of timeout ######## # end of cronometer $t1 = gettimeofday; $elapsed = $t1 - $t0; print "Content-type: text/html\n\n"; print "Query took $elapsed seconds but the alarm didn't work!";
I'm using Perl 5.8.7, Win2K and mysql 4.1. And this is a mod_perl script.

Any ideas?

Thanks a lot

Andre