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


In reply to Unable to setup timeout for DBI execute call by Andre_br

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.