in reply to Sequential processing with fork.

By far the easiest thing to do is to put your 33 requests into a shared queue, then spawn however-many workers (10) you need to have. Each worker pops a request off the queue until there are no more; then, it dies.

Replies are listed 'Best First'.
Re^2: Sequential processing with fork.
by Anonymous Monk on Aug 04, 2015 at 21:56 UTC

    Words, words, words. If it was that easy you would have shown runable code. :)

      Quite easy.

      use forks; use Thread::Queue qw( ); # 3.01+ use constant NUM_WORKERS => 10; sub work { my ($client) = @_; print("$client start...\n"); sleep(3 + int(rand(2))); print("$client done.\n"); } { my $q = Thread::Queue->new(); for (1..NUM_WORKERS) { async { while (my $client = $q->dequeue()) { work($client); } }; } $q->enqueue($_) for 1..33; $q->end(); $_->join() for forks->list(); }
        Can't locate object method "list" via package "forks" at ./threadqueue +.pl line 33. Perl exited with active threads: 10 running and unjoined 0 finished and unjoined 0 running and detached

        I was unable to install "forks" eg( use forks) on my windows server 2012 running Dwimperl. So I couldn't test the above code.

        The problem I am having is that each of the processes take from 30min to occasionally 2.5 hours to finish, the "wait" seems to be giving up. I can successfully run the first batch of ten, but no method I have tried has ever started the next process when one of the first ten finishes...

        Is there a wait time limit var I can adjust? Or is that machine specific?

        ~~~~~~~~~ I'm unique, just like everybody else! ~~~~~~~~~
        Yes, and yes. I'm running windows server 2012 with dwimperl.