develooper Front page | perl.ithreads | Postings from September 2010

Re: Killing a thread

Thread Previous | Thread Next
From:
Jerry D. Hedden
Date:
September 29, 2010 05:48
Subject:
Re: Killing a thread
Message ID:
AANLkTinQEvpaby8cH+N0E1hjx=b_bgG8C=Tx-LLu5Vdn@mail.gmail.com
Danny Wong wrote:
> Here is my situation. I started, say 10 threads, executing
> some command, 1 or 2 of them is hanging for over 2 hours.
> I want to put in some logic that if the thread run time
> passes an hour threshold kill that thread or return and
> fail the thread. Any ideas on how I can accomplish this
> task? Thanks.

This problem is addressed in the 'examples/pool.pl' file in
the 'threads' distribution on CPAN.  From the POD (note the
third bullet):

    NAME
        pool.pl - Simple 'threads' example

    DESCRIPTION
        A simplistic example illustrating the following:
        *   Management of a pool of threads
        *   Communication between threads using queues
        *   Timing out and cancelling threads
        *   Interrupting a threaded program
        *   Cleaning up threads before terminating

However, if the 'hung' threads are stuck on some system
call, then the above will not work because of Perl's "safe
signals".  You'll need to read the section called "Deferred
Signals (Safe Signals)" in "perldoc perlipc".

Thread Previous | 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