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 <[EMAIL PROTECTED]> 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.
>

Reply via email to