Hello Perl Monks,

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

In reply to Thread::Pool shutdown dies after abort by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.