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

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(); }

Replies are listed 'Best First'.
Re^4: Sequential processing with fork.
by Anonymous Monk on Aug 06, 2015 at 04:21 UTC
    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
Re^4: Sequential processing with fork.
by Kelicula (Novice) on Aug 08, 2015 at 16:35 UTC

    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.

        Windows Server 2012 R2, but I'm not starting it via IIS it's just an icon on the desktop that I double click. I have NEVER been able to get this to work with ANY of the given examples.
Re^4: Sequential processing with fork.
by Kelicula (Novice) on Aug 09, 2015 at 03:45 UTC
    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 :)