Hi,
Thanks for the suggestion of using a shared array for $end_ne . I was initially using a signal to kill the thread and the restart it, when I change dto just setting an array I didn't think to use the array. Will change that.
You asked me to post the command and control code:
my @hosts = keys %nes; my @hosts_ok; my $max_threads = $config->val($section,'MaxThreads'); for my $threadno (0 .. ($max_threads-1)){ if (@hosts){ my $host = shift (@hosts); $thread_ip[$threadno] = $host; $thread_result[$threadno] = 0; $thread_time[$threadno] = time(); push @threads, threads->create('get_ne_data',$threadno); $threads[@threads-1]->detach(); write_log ('MAIN','STARTING THREADS',1,'001b','Starting thread +',$threads[@threads-1]->tid(),'NE',$host); sleep(1); } } while (@hosts){ for my $threadno (0 .. (@threads-1)){ if ($threads[$threadno] and $threads[$threadno]->is_running() +){ if ($thread_result[$threadno]){ # thread as returned if ($thread_result[$threadno] == 2){ write_log ('MAIN','PROCESSING NES',2,'001c','Threa +d',$threads[$threadno]->tid(),'NE',$thread_ip[$threadno],'Finished OK +'); push @hosts_ok, $thread_ip[$threadno]; } else { write_log ('MAIN','PROCESSING NES',2,'001d','Threa +d',$threads[$threadno]->tid(),'NE',$thread_ip[$threadno],'Finished NO +K'); } $thread_time[$threadno] = time(); $thread_result[$threadno] = 0; if (@hosts){ $thread_ip[$threadno] = shift @hosts; } else { # print "\tFINISHED\n"; $thread_ip[$threadno] = 'FINISHED'; } write_log ('MAIN','PROCESSING NES',2,'001e','Thread',$ +threads[$threadno]->tid(),'is being assigned',$thread_ip[$threadno]); } elsif ($thread_time[$threadno] < (time-60) ){ write_log ('MAIN','PROCESSING NES',2,'001f','Thread',$ +threads[$threadno]->tid(),'NE',$thread_ip[$threadno],'Being killed'); # print "\t$thread_ip[$threadno] is being killed\n"; $threads[$threadno]->kill('STOP'); $thread_time[$threadno] = time(); $thread_result[$threadno] = 0; if (@hosts){ $thread_ip[$threadno] = shift @hosts; } else { # print "\tFINISHED\n"; $thread_ip[$threadno] = 'FINISHED'; } write_log ('MAIN','PROCESSING NES',2,'0020','Thread',$ +threads[$threadno]->tid(),'is being assigned',$thread_ip[$threadno]); } } else { # for some reason we don't have a thread here - possibly sto +pped due to long run time # print "\tTrying to restart thread\n"; if (@hosts){ my $host = shift (@hosts); $thread_ip[$threadno] = $host; $thread_result[$threadno] = 0; $thread_time[$threadno] = time(); $threads[$threadno] = threads->create('get_ne_data',$t +hreadno); $threads[$threadno]->detach(); write_log ('MAIN','PROCESSING NES',4,'0021','THREAD NE +EDS RESTARTING',$threads[$threadno]->tid(),'NE',$thread_ip[$threadno] +); } } } sleep(1); } write_log ('MAIN','',2,'0022','All hosts started'); my $threads_running = 1; while ($threads_running){ $threads_running = 0; for my $threadno (0 .. (@threads-1)){ if ($threads[$threadno] and $threads[$threadno]->is_running() +){ $threads_running++; if ($thread_result[$threadno]){ # thread as returned if ($thread_result[$threadno] == 2){ write_log ('MAIN','CLEARUP',2,'0022','Thread',$thr +eads[$threadno]->tid(),'NE',$thread_ip[$threadno],'Finished OK'); push @hosts_ok, $thread_ip[$threadno]; } else { write_log ('MAIN','CLEARUP',2,'0023','Thread',$thr +eads[$threadno]->tid(),'NE',$thread_ip[$threadno],'Finished NOK'); } $thread_ip[$threadno] = 'FINISHED'; $thread_result[$threadno] = 0; } elsif ($thread_time[$threadno] < (time-60) ){ write_log ('MAIN','CLEARUP',2,'0024','Thread',$threads +[$threadno]->tid(),'NE',$thread_ip[$threadno],'Being killed'); $threads[$threadno]->kill('STOP'); $thread_time[$threadno] = time(); $thread_result[$threadno] = 0; $thread_ip[$threadno] = 'FINISHED'; } } } }
In reply to Re^6: Perl Thread Quitting Abnormally
by Anonymous Monk
in thread Perl Thread Quitting Abnormally
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |