in reply to Re: Sequential processing with fork.
in thread Sequential processing with fork.

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

Replies are listed 'Best First'.
Re^3: Sequential processing with fork.
by ikegami (Patriarch) on Aug 05, 2015 at 18:11 UTC

    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
        its threads->list, not forks->list
      Yes, and yes. I'm running windows server 2012 with dwimperl.

        It sounds like your control program is getting killed by something. I'd recommend opening a shell window and running your control program in that.

        Actually I'd recommend running your control program on a Linux machine :)

      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! ~~~~~~~~~

        Are you running your control program under a webserver? Webservers will time things out on you.

        Also, is the control program running on Windows? Fork is faked on Windows.

        Please state OS.