Control the length of Fork Super queue

2019-07-19 17:02发布

问题:

Continuing from my last question Access element across multiple hash of hash of arrays

I have this bit of code,

use Forks::Super;
foreach my $special_type (keys %test_variables) {
        my $last_job = undef;
        foreach my $test_module (keys %{$test_variables{$special_type}}) {
                foreach my $set_of_tests ($test_variables{$special_type}{$test_module}) {
                        foreach my $test (@$set_of_tests){
                                print "Starting $test\n";
                                my $job = fork {
                                    name => "$special_type/$test_module/$test",
                                    cmd => "nosetests -m $special_type/$test_module/$test",
                                    depend_on => $last_job
                                };
                                $last_job = "$special_type/$test_module/$test";
                                print "Queue last job:$last_job \n\n\n\n";
                        }
                }
        }
}

but the length of the queue that is formed seems to be fixed at 1. So basically only the second process waits for the first one to get completed.

Though I had imagined/wished that the full queue to be built like 5 waits for 4 , 4 waits for 3 , and 3 wait for 2 and 2 waits for 1.

Question : How do I build the whole queue right at the start?

回答1:

Set $Forks::Super::ON_BUSY to queue or use the module like

use Forks::Super ON_BUSY => 'queue';

The default setting is block, which would stop execution the first time you set up a job with a dependency.

Maybe queue should be the default, or at least it should be the default for jobs with dependencies.