Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Time to cancel a thread
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Javier Terceiro
03-25-08 12:57 AM


Re: Time to cancel a thread
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.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Jerry D. Hedden
03-25-08 03:57 AM


Re: Time to cancel a thread
Hello,

Prefect, if I use this package with a thread, I can to cancel this
process when I like, but I did not see in the documentation on how to
specify the maximum time out that a process can take before being
canceled. How can I do this if possible?

Thank you.


2008/3/25, Jerry D. Hedden <jdhedden@cpan.org>:
> Look at the module Thread::Cancel on CPAN.  It provides the
>  capabilities you're looking for.
>

--
A greeting,

Javier.

Report this thread to moderator Post Follow-up to this message
Old Post
Javier Terceiro
03-25-08 01:41 PM


Re: Time to cancel a thread
>  Prefect, if I use this package with a thread, I can to cancel this
>  process when I like, but I did not see in the documentation on how to
>  specify the maximum time out that a process can take before being
>  canceled. How can I do this if possible?

Check the example in the Thread-Cancel module from CPAN.
It's under 'examples' and is called 'cancel.pl'.

Report this thread to moderator Post Follow-up to this message
Old Post
Jerry D. Hedden
03-26-08 12:49 AM



Thousands of MP3s are waiting for you at http://mp3files4free.com/

Our new hits:
"Angry Samoans - Different World" free mp3 download
"Morcheeba - Over and Over" free mp3 download
"Goran Bregovic - Talijanska" free mp3 download
"Babes In Toyland - Catatonic" free mp3 download
"Dance - Various Artists - Q-Bur
n's Abstract Message - Puff the Magic" free mp3 download
"Alice Gomez With Madalyn Blanchet
t and Marilyn Rife - Desert Wind" free mp3 download
"Moxu
se - Eda" free mp3 download
"Alkehol - Vsechno Je Jinak" free mp3 download
"Jerry Reed - Calles de Fuego. The Blasters. 
Blue Shadows" free mp3 download
"Iggy Pop - Shoeshine girl" free mp3 download
"London After Midnight - Sally's Song" free mp3 download
"Penumbra - Turn Then Off" free mp3 download
"Easy Listening - Various Artists - T & Ma
sson - Procession" free mp3 download
"Fred Hersch - Phantom Of The Bopera" free mp3 download
"UNKLE Sounds - Bonus Material Edit Strikes B
ack Part. 6" free mp3 download
"Bananarama - Love In The First Degree" free mp3 download[/URL
]
[URL=http://www.mp3files4free.com/mp3download.php?aid=218571&song=Estradasphere-Pa
lace_of_Mirrors]"Estradasphere - Palace of Mirrors" free mp3 download
"Hans Zimmer - Pilgrim's Chant/In the Land 
of the Ancestors" free mp3 download
"Dan Swano - I Carry A Secret" free mp3 download
"Cher - Have i stay too long" free mp3 download
"Feeder - Frequency" free mp3 download
"Blues - Various Artists - Slow Leake (Lafayett
e Leake)" free mp3 download
"Blues - Various Artists - Goin' Down Slow (How
lin' Wolf)" free mp3 download
"Gary Moore - Hard Times" free mp3 download

Report this thread to moderator Post Follow-up to this message
Old Post
Emdesfalo
04-02-08 11:27 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ithreads archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:46 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.