in reply to DBI and fork() on Win32

What you're doing is dangerous already on Linux/Unix. Not all DBDs support fork() on Unix. You take care to disconnect, which might prevent most of the problems. On Windows, fork() is only emulated through threads, and thus, all of the caveats in the DBI documentation about threads apply there. You should have one (and only one) DBI connection in your process. If you want to do parallel processing using a database (which I doubt will be efficient), then I recommend you launch separate child processes through system(1, ...) or system("start $cmd") to have really separate DBI handles.

Replies are listed 'Best First'.
Re^2: DBI and fork() on Win32
by FloydATC (Deacon) on Feb 10, 2009 at 14:43 UTC
    Thanks, I think I understand, it's not the handle but the driver that causes problems?

    Unfortunately, system() doesn't help because I need each job to be executed in paralell and I don't want to sit around and wait for each one of them.

    I have tried rewriting &child() like this:

    sub child { my $job = shift; exec("perl", "child-script", $job); exit; # Just in case }
    ...but DBI still crashes with the same message.

      exec is not the solution. I didn't show a plain system() call but system(1, ...), which is mentioned in perlport, and which executes the program separately from the main program. This is mostly the same as system("start $cmd"); except that the latter involves the shell.

        I'm ready to just give up... Got rid of the fork() and replaced with
        system(1, "perl", "child-script", $job);
        This crashes too, even when 'child-script' contains just two lines:
        print "hello world\n"; exit;