I've encountered a similar problem with alarm().

Here's a piece of working production code that
succesfully uses alarm() with DBI.

----------------------------------------

   my $dbh = '';

   # database connection will cause perl to 'die'
   # will just exit the eval block so we can check
   # the value of $dbh

   eval {
      local $SIG{ALRM} = sub {
      $logFile->printflush("Connection to $db timed out\n");
         die "connection timeout\n";
      };

      alarm $dbup::parms{connectionTimeOut};

      $dbh = new PDBA::CM(
         DATABASE => $db,
         USERNAME => $dbup::uptime{$db}->{username},
         PASSWORD => $password
      );

   };

   # the alarm reset must be outside the eval{}
   alarm 0;

------------------------------------

The trick is to use eval to create the connection.

Set the alarm inside the eval block, reset it outside the eval block.

Jared





On Wednesday 27 November 2002 01:49, Tim Bunce wrote:
> Got a moment to gve this more thought...
>
> > ----
> > #!/usr/SD/perl/bin/perl
> >
> > #use DBD::Oracle;
> > use DBI;
> >
> > $SIG{ALRM} = sub { print "Caught alarm\n"; };
> >
> > alarm (2);
> > $dbh = DBI->connect('dbi:Oracle:eman', 'eman', 'eman');
> > alarm (0);
> >
> > sleep(5);
> > print "Success\n";
> >
> > ----
> > If the "use DBD::Oracle" line is uncommented, the script succeeds.  If
> > commented out, it fails, and the $SIG{ALRM} handler doesn't work either-
> > it just prints "Alarm Clock" and exits.
> >
> > It appears that the oracle libraries are monkeying with the signal
> > handlers?
>
> May actually be Solaris when it dynamically loads a library that
> uses threading into an application that wasn't linked for threading.
>
> > I'm not really happy with the "use DBD::Oracle" workaround at this point-
> > i'd hate to miss some script somewhere while trying to add it.
> >
> > If there's a way to fix this in DBD, i'd prefer that, certainly.
>
> Try reconfiguring (and rebuilding) perl to support threads. Don't
> actually _use_ the threads support, but the fact it's there (ie
> perl was linked with -lthread) may be enough to avoid the problem.
>
> Please let us know if it helps.
>
> Tim.

Reply via email to