in reply to Completely Random Stall

I'd like to second BrowserUK's advice, esp re use strict, warnings.
Also, replace your system() calls with the built-in Perl equivalents, which will give you better error handling and remove the process-creation overhead you're getting.
As well, check for errors in opendir() : http://perldoc.perl.org/perlopentut.html.
BTW, forking != threading.

Replies are listed 'Best First'.
Re^2: Completely Random Stall
by expresspotato (Beadle) on Apr 27, 2009 at 18:09 UTC
    Hi Monks! I'm still having the same problems... A few hundred threads in, the script decides to stop working. How should I be cleaning up after the thread has finished? Any help is appreciated.
    #! /usr/bin/perl use threads; $|++; print "Running...\n"; while(1){ opendir(DIR2,"./bgthread/process"); @list3 = readdir(DIR2); close( +DIR2); $line = ""; @items = ""; foreach (@list3){ $line = $_; chomp($line); if (($line ne ".") && ($line ne "..")){ ($buffer,$do,$torrent) = split(/\-\.\-/,$line); print "Sending ($line)\n"; $thr = threads->new(\&do_thread); $thr->detach; } } if (-e "./bgthread_refresh"){ exit; } sleep(1); #system("sleep 0.5"); print ":"; } sub do_thread(){ system("perl bgthread_processor.pl $line"); #goto &nothing; } sub nothing(){ #Do nothing... undef $line; }