I am mystified by the behavior of "alarm" in conjunction with 
Postgres/perl/DBD.  Here is roughly what I'm doing:

  eval {
     local $SIG{ALRM} = sub {die("Timeout");};
     $time = gettimeofday;
     alarm 20;
     $sth = $dbh->prepare("a query that may take a long time...");
     $sth->execute();
     alarm 0;
  };
  if ($@ && $@ =~ /Timeout/) {
     my $elapsed = gettimeofday - $time;
     print "Timed out after $elapsed seconds";
  }

Now the mystery: It works, but it hardly matters what time I use for the alarm call, the actual 
alarm event always happens at 26 seconds.  I can set "alarm 1" or "alarm 20", 
and it almost always hits right at 26 seconds.

Now if I increase alarm to anything in the range of about 25-60 seconds, the actual alarm arrives 
somewhere around the 90 second mark.  It seems as though there are "windows of 
opportunity" for the alarm, and it is ignored until those "windows" arrive.

Anyone have a clue what's going on and/or how I can fix it?

A secondary question: It appears that $sth->cancel() is not implemented in the 
Pg DBD module.  Is that true?

Thanks,
Craig

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to