Comment 3 for bug 1581072

Revision history for this message
John Gravatt (john-gravatt) wrote :

Here is a workaround where I wrapped the execute() with signal blocking. This worked perfectly in my testing...

======

#!/usr/bin/env perl

use Modern::Perl;
use DBI;
use POSIX qw(signal_h);

use vars qw($OldSig);

my $dbh = DBI->connect('dbi:mysql:host=127.0.0.1;database=mysql');
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 0;

$SIG{CHLD} = \&catch_child;
say "my pid: $$";

my $sql = qq{
        select sleep(30);
};
my $sth = $dbh->prepare($sql);

block_signals();
$sth->execute;
unblock_signals();

while(my @aref = $sth->fetchrow_array) {
        sleep 1;
}

say "query done";

##############

sub block_signals {

        say "blocking signals";

        $OldSig = POSIX::SigSet->new;

        my $newsig = POSIX::SigSet->new;
        $newsig->fillset;

        sigprocmask(SIG_BLOCK, $newsig, $OldSig);
}

sub unblock_signals {

        say "unblocking signals";

        sigprocmask(SIG_SETMASK, $OldSig);
}

sub catch_child {

        say "in catch_child()";
}