develooper Front page | perl.ithreads | Postings from July 2008

Thread::pool

Thread Next
From:
Javier
Date:
July 29, 2008 05:24
Subject:
Thread::pool
Message ID:
602eb19e0807290523y13b88ff2l8608a467a20480c3@mail.gmail.com
Hi,

I have a problem with the module Thread::Pool-0.32.
I need to set my script as a daemon, but when i use this module the program
kill the threads.

The output of my script is:

        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        starting a new work with
        Perl exited with active threads:
                20 running and unjoined
                0 finished and unjoined
                0 running and detached

And the source code is:
= = = = = = = = * * * * * * * * * * = = = = = = = =
my $pool = Thread::Pool->new(
                {
                       optimize => 'memory',
                       do => \&check_system,
                       pre => sub {shift; print "starting a new work with
@_\n" },
                       post => sub { print "stopping the work\n" },
                       frequency => 10,
                       autoshutdown => 1,
                       workers => 20,
                       maxjobs => 100,
                       minjobs => 10,
                }
        );

sub daemon
{
        chdir "/";
        open STDIN, '/dev/null';
        fork && exit;
        setsid();
        if (open PID, '>', '/var/run/faxqr.pid')
        {
                print PID "$$\n";
                close PID;
        }
}

daemon();
scan_files();
= = = = = = = = * * * * * * * * * * = = = = = = = =

First i initialice the pool and then i set the process as a daemon. Then i
call the scan_files() function.

I also test to initialice the pool inside the daemon() function and between
daemon() and scan_files(). Doing that, the output is blank, but it doesn't
work.

Thank you for your help.

-- 
A greeting,

Javier.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About