How can I make DBD :: Pg reliable?

Why doesn't this code execute the signal handler until $ sth-> execute is complete? And more importantly, how can I fix this?

#!/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"; 
+4
source share
3 answers

Instead, consider the Pg function asynchronous request .

+2
source

Due to changes in the way Perl processes signals (the so-called "safe signals" from 5.8.0), you will need to use Perl :: Unsafe :: Signals so that your die() works when $sth->execute is executed .

+1
source

There is AnyEvent :: Pg which allows PostgreSQL to be queryed asynchronously, however it is not DBI compatible and this will force you to rewrite the application / script on top of AnyEvent .

+1
source

All Articles