Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageLook 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.
>
Post Follow-up to this messageHello, 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.
Post Follow-up to this message> 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'.
Post Follow-up to this messageThousands 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.