views:

41

answers:

1

I am writing a program to extract data from a bunch of text files and stuff it into DB. All of my commands currently have the form similar to this (with different queries):

$query = "INSERT INTO relations (relation_type_id, confidence) VALUES ($reltypeid, $conf)";
print "$query\n";
$result = $conn->query($query);
$relid = $result->insertid();
...

However, I have noticed random errors pop up during the execution, like this:

INSERT INTO relations (relatiDBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
on_type_id, confidence) VALUES (12, 0.709310711263845)

If I run it with perl -w, I get this:

INSERT INTO relations (relatiUse of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/DBD/mysql.pm line 211.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/DBD/mysql.pm line 211.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
on_type_id, confidence) VALUES (12, 0.709310711263845)

Now what worries me is that clearly some multithreading crap is going on - the program does not die, and the error is inserted in the middle of a print - and I have no clue how to debug it. For the record, I myself am not forking or threading anywhere except backticking zcat, and these are all the packages that are included:

use Switch;
use File::Basename;

and in an included pm:

use Mysql;
use Exporter qw(import);

Also, I've googled the error message, and I can't get the full hit (name & location). Just the error name ("Query was empty") hit an article where the poster was accessing a connection from two subsequently forked processes.

One more thing of note: the phenomenon is deterministic. The errors always appear in the same place, as long as the code is intact. If I change the output (for instance, insert some marker lines like print "---"; to separate my record blocks), the errors occur earlier (can't really say if it's on the same byte-count of output or not).

Is there a way to disable multithreading in perl? How do I catch the bugger? What is that error message about?

UPDATE: The problem was the combination of stdout buffering, misleading Google hit, perl directory name and a major case of brain fart.

+1  A: 

Please post the whole Perl program.

Nothing I see here makes me think that this is a multithreading issue. Unless you're asking for threads somewhere, you aren't getting multiple threads in Perl5.

As a wild guess, due to the extra print statements changing the results it feels like a buffering issue. Try hotting your STDOUT with $|=1;

masonk
Thank you so much for the `$|` - it really was a buffering issue (I was deceived by the Google result and the `x86_64-linux-thread-multi`).
Amadan
That naming convention is for machine-specific optimized Perl libraries. It doesn't mean that they are multithreading, it just means that they reserve the right to multithread. The better libraries are thread safe, meaning you would never know that they're doing it.For more information about buffering, check out Suffering From Buffering?: http://perl.plover.com/FAQs/Buffering.html
masonk
Yeah, I understand. I was beginning to get paranoid and thinking MySQL library was doing shit behind my back :) So relieved that wasn't the case. I understood the buffering point as soon as I took a look at `perlvar` to see what `$|` meant, but thanks for the link.
Amadan