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

Re: Time to cancel a thread

Thread Previous | Thread Next
From:
Jerry D. Hedden
Date:
March 24, 2008 20:25
Subject:
Re: Time to cancel a thread
Message ID:
1ff86f510803241735y2868fcb3w9599d16d6d372d6c@mail.gmail.com
Look at the module Thread::Cancel on CPAN.  It provides the
capabilities you're looking for.

On Mon, Mar 24, 2008 at 7:24 PM, Javier Terceiro <correolista@gmail.com> wrote:
> Hello list,
>
>  I am writing a daemon. I have a daemon that it check a folder and then
>  throws both threads exist as files. It's well, the problem is that
>  each thread need it ends at a certain time (defined by default). If
>  this does not complete the work to be cancelled. For example, if it is
>  making a connection to a website and it does not respond in 2 minutes,
>  until the process completes and the thread too, running a particular
>  code before.
>
>  I was looking like doing and I did not find anything. Any thoughts on
>  how to do that
>
>  My source code is:
>
>  #!/usr/bin/perl -w
>
>  use strict;
>  use warnings;
>  use AnyData;
>  use Sys::Syslog qw(:standard :macros);
>  use POSIX qw(setsid);
>  use threads;
>  use threads::shared;
>
>  sub mail
>  {
>         sleep(2);
>         syslog LOG_INFO, "thread for mail";
>         my $file_name = shift;
>         ...
>         # If you spent 2 min, canceled
>         # source cancel
>         syslog LOG_INFO, "Surpassed time";
>
>         # else
>         syslog LOG_INFO, "Process completed";
>  }
>
>  sub scan_files
>  {
>         my $DIR = "workq/";
>         while(1)
>         {
>                 opendir(DIRHANDLE, $DIR) || die "ERROR: $DIR not read\n";
>                 foreach (readdir(DIRHANDLE))
>                 {
>                         if (!-d $_)
>                         {
>                                 threads->new(\&mail, $_);
>                         }
>                 }
>                 closedir DIRHANDLE;
>                 sleep(10);
>         }
>  }
>  ...
>  ...
>  ...
>
>  --
>  A greeting,
>
>  Javier.
>

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