rjahrman has asked for the wisdom of the Perl Monks concerning the following question:

I've written a multi-threaded command-line script. When running it (and it runs for several hours or more), I occasionally get "Perl Command Line Interpreter has encountered an error and needs to close" pop-ups at seemingly random places in the program. Is this a bug in Perl (I've heard that threads in Windows have bad memory management), or a bug in my code?
  • Comment on Windows XP: Perl Command Line Interpreter Encountered an Error

Replies are listed 'Best First'.
Re: Windows XP: Perl Command Line Interpreter Encountered an Error
by arden (Curate) on Mar 21, 2004 at 06:00 UTC
    rjahrman, before we can identify if it might be a bug in your code, you'll have to show us some of it. My personal experience with threads, Perl, & Windows is not a pretty one, and I've heard many other testimonials from others to this point too. Do us a favor and post your code (inside <READMORE> tags assuming it's more than 20 lines of code) and let us take a look at it.

    Another thing that will help us is to know a bit more about your program. What kind of input does it take? What is it supposed to do? How much memory does your system have in it? Is it possibly busy doing other things (IIS, Exchange, etc)?

    - - arden.

Re: Windows XP: Perl Command Line Interpreter Encountered an Error
by wolfi (Scribe) on Mar 21, 2004 at 11:49 UTC
    windows'll crash because ya sneezed on the monitor.
    seriously though...

    1) yes, windows is horrible w/memory management and often fails to refresh its virtual memory pages very well. (Which, will cause the system to crash eventually.)

    2) that error tells us about as much as it tells you. Symptoms, more information, and error code #'s - and as arden said... the perl code - would be helpful. (it might have nothing to do w/the code... but it would help to know, what it is - so at least, we could rule that out)

    ~something to check: go to CONTROL PANEL -> ADMINISTRATIVE TOOLS -> EVENT VIEWER and browse thru there. XP will usually record little notes there about successes and failures... maybe some hint will be there.

    (You could always try reinstalling your perl port too.)

    ...anyone know if perl has its own error-log?

Re: Windows XP: Perl Command Line Interpreter Encountered an Error
by Anonymous Monk on Mar 21, 2004 at 18:01 UTC
    The event log said: Faulting application perl.exe, version 5.8.0.806, faulting module perl58.dll, version 5.8.0.806, fault address 0x00045400.

    I'm running this on my local computer. It has 512MB RAM, but it's not a live server. It was running other stuff at the same time, though nothing that's much of a resource-hog. I will post part of my code below, though I'm going to take out the middle that's just a bunch of SQL calls, regexes, and logarithmic functions. Wouldn't want someone to steal my code . :)
    use threads; use threads::shared; # I used to use this, but I probably don't need +it any more print "THREAD SPAWNED.\n"; $thr1 = threads->new(\&mainsub,0); $thr1->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr2 = threads->new(\&mainsub,1); $thr2->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr3 = threads->new(\&mainsub,2); $thr3->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr4 = threads->new(\&mainsub,3); $thr4->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr5 = threads->new(\&mainsub,4); $thr5->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr6 = threads->new(\&mainsub,5); $thr6->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr7 = threads->new(\&mainsub,6); $thr7->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr8 = threads->new(\&mainsub,7); $thr8->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr9 = threads->new(\&mainsub,8); $thr9->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr10 = threads->new(\&mainsub,9); $thr10->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr11 = threads->new(\&mainsub,10); $thr11->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr12 = threads->new(\&mainsub,11); $thr12->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr13 = threads->new(\&mainsub,12); $thr13->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr14 = threads->new(\&mainsub,13); $thr14->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr15 = threads->new(\&mainsub,14); $thr15->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr16 = threads->new(\&mainsub,15); $thr16->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr17 = threads->new(\&mainsub,16); $thr17->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr18 = threads->new(\&mainsub,17); $thr18->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr19 = threads->new(\&mainsub,18); $thr19->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr20 = threads->new(\&mainsub,19); $thr20->detach; while (1) { # so that the main thread doesn't close # not sure if I need this anymore, though # (I used to print some statistics here) sleep 1; } sub mainsub { my ($which) = @_; use LWP::Simple; require "En.pm"; # En.pm is Lingua::Stem . . . I couldn't get it to install normally fo +r some reason use DBI; my $dbh = DBI->connect("DBI:mysql:crawler:localhost", "root", "", { RaiseError => 1 }) or die "Can't connect: ", $DBI::errstr; while (1) { # I close the program manually. . . . } # end of while(1) }
      Just as an aside ... looking at your code, why not simply write
      my @threads; for my $i (0..19) { print "THREAD SPAWNED.\n"; $threads[$i] = threads->new(\&mainsub, $i); $threads[$i]->detach; sleep 1; }
      instead of this
      print "THREAD SPAWNED.\n"; $thr1 = threads->new(\&mainsub,0); $thr1->detach; sleep 1; print "THREAD SPAWNED.\n"; $thr2 = threads->new(\&mainsub,1); $thr2->detach; sleep 1; # ...
      'red flag' code repetition.

      -- Hofmator

Re: Windows XP: Perl Command Line Interpreter Encountered an Error
by wolfi (Scribe) on Mar 23, 2004 at 12:58 UTC

    i thought, i should get back with you, since i suggested you look at the event viewer there (which wasn't much help, i'm afraid).

    it's kind of like the blind leading the blind to help you out w/this, since i'm very new to modules here. But some thoughts i've had...
    1) you've created a infinite loop somewhere
    2) your 'crawler' is indexing too much or keeping too much in its memory
    3) and i'm really not sure about this... but maybe calling all those modules repeatedly within a subroutine, which itself is repeatedly called... well, i don't know, if that'd be a problem, but it might.

    what i can say is, that those monks, who are more experienced and could help you out, may not bother, if you do not submit all the code. It isn't that they want to steal your code, but that it's almost impossible to diagnose a problem without all the facts. (Besides, if they can fix your problem, i'm sure, they can write the code for themselves already.)

    just some thoughts. Sorry i couldn't help much.
    I do hope, you find the solution to your problem.