Thanks everyone for the responses. They're a little over my head though. I
was referred to this list by someone on the PERL beginners list-serve, since
my problem is Windows related. But from what I can tell, this list doesn't
seem to be very beginner-oriented. :) And honestly, the content on the
beginners list was often over my head! I've read PERL for Dummies by Paul
Hoffman and understand most of it and have been able to do some simple things.
But this infinite loop problem is the one thing keeping me from my main
programming goal for which I learned about PERL in the first place. If anyone
can give me the solution in a patient, dumbed-down sort of way I'd be most
grateful!
e.g. As for Chris's advice below, I wouldn't know how to start a separate
thread, or how to use Win32::Process. And as for Rob's advice:
The alarm() function now works on Windows:
C:\_32\pscrpt>type try.pl
use warnings;
use strict;
alarm(2);
while(1) {}
C:\_32\pscrpt>perl try.pl
Terminating on signal SIGALRM(14)
C:\_32\pscrpt>
Is this code? The "C:\" lines look more like something you'd type in a DOS
window.
Here's what I wrote before knowing about the Windows issue. As a test, I
made 4 little programs, named infinite1.pl, infinite2.pl etc. The 3rd has an
infinite loop and the others don't. The following code ought to tell me that
#3 lasts more than 9 seconds, but not the others.
for($number = 1; $number < 5; $number +=1) {
$ProgramName = "infinite" . $number . ".pl";
eval {
local $SIG{ALRM} = sub { die "$ProgramName timed out\n" };
alarm 9;
require $ProgramName or die "Require failed\n";
alarm 0;
};
print $@;
if($@) {
if($@ =~ /timed out/) {
print "timeout\n"; # timeout
} else {print "some other error\n"; # some other error
}
}
}
If the alarm function now works on Windows, why doesn't this code give me
the results I expect? Might it matter than I'm using Windows ME? What about
my version of PERL? It's the one from the CD that came with that book. 5.6 I
think - I can check if it matters.
Thank you so much,
Chris
Chris Wagner <[EMAIL PROTECTED]> wrote: I would start by executing the sub
program in a seperate thread. That way
the main thread can keep an eye on it and decide if it's run too long and
then do something about it. Another way to do it is with Win32::Process and
then kill them after some time span.
At 01:35 PM 1/26/2007 -0800, Chris Rodriguez wrote:
>Hello,
> I have a program that runs other programs (through require statements
and what not). There's a problem in that some of these sub-programs may
have infinite loops, which would cause the main program to hang. I'd like
the main program to just detect such and go on to the next one. How might
I do that? The alarm function seemed to be the way to go - but not with
Windows. Can I do something with wait and create? Any other ideas?
---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs