Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am using Thread::Pool to create a pool of threads (workers) (let's say 2) where my 10 processes can be queued and run in parallel, 2 at a time.
At some stage I want to abort the program. Usually some processes are finished, some are being processed and some are still pending to be processed in the pool.
What I do is to use the Thread::Pool->abort() method which, as I understood it, removes all pending processes and waits for all processed being processed right now. As soon as these are finished, then abort() returns.
Am I right to assume that at this stage, it is safe and proper to use Thread::Pool->shutdown() and then exit my program?
Unfortunately, when I call shutdown, I get a 'die' with the message:
Shutting down pool while there are still jobs to be done at /Library/Perl/5.10.0/Thread/Pool.pm (loaded on demand from offset 20056 for 2434 bytes) line 780
line 780 of Pool.pm is:die "Shutting down pool while there are still jobs to be done" if $belt->onbelt;
I am running:
This is perl, v5.10.0 built for darwin-thread-multi-2leve
Below is an example code which demostrates the problem:
#!/usr/bin/perl use Thread::Pool; use strict; use warnings; sub my_process { print "Hi i am a spawned sub and I am sleeping. my ID is $_[0]\n"; sleep(10); } my $pool = Thread::Pool->new({ workers => 2, maxjobs => 1, do => \&my_process }); my ($i); for($i=0;$i<10;$i++){ $pool->job($i); } print "sleep for 5\n"; sleep(5); print "will now abort\n"; $pool->abort(); print "will now shutdown\n"; $pool->shutdown(); print "all is normal but unfortunately i die before i come here\n"; exit(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Thread::Pool shutdown dies after abort
by lidden (Curate) on Jun 29, 2011 at 13:11 UTC | |
|
Re: Thread::Pool shutdown dies after abort
by dcmertens (Scribe) on Jun 29, 2011 at 13:20 UTC | |
by Anonymous Monk on Jun 29, 2011 at 13:56 UTC | |
|
Re: Thread::Pool shutdown dies after abort
by BrowserUk (Patriarch) on Jun 29, 2011 at 15:59 UTC | |
by locked_user sundialsvc4 (Abbot) on Jun 30, 2011 at 01:35 UTC | |
by Anonymous Monk on Jul 04, 2011 at 14:48 UTC | |
by BrowserUk (Patriarch) on Jul 04, 2011 at 15:40 UTC |