in reply to Re^4: How to timeout if a call to an external program takes too long
in thread How to timeout if a call to an external program takes too long
Okay, but are you sure your tests actually show that the backticks were interrupted?
What do you mean by "interrupted"? Certainly I received and processed the alarms before the backticks finished executing. I don't know whether the processes that the backticks started were killed, but that wasn't the problem I was trying to solve anyway.
my $start = time; sub exec_time { return time - $start } alarm 5; $SIG{ALRM} = sub { printf "alarm (%d)!\n", exec_time() }; my $yawn = `sleep 10 ; echo "yawn"`; printf "(%d) yawn? $yawn\n", exec_time(); __END__ alarm (5)! (10) yawn? yawn
See? And here's the other one:
my $start = time; sub exec_time { return time - $start } my $yawn; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 5; $yawn = `sleep 3600 ; echo "yawn"`; alarm 0; }; printf "Time: %d\n", exec_time(); print $@ ? 'Timed out.' : 'Finished.'; print "\n"; print "yawn? $yawn\n"; __END__ Time: 5 Timed out. yawn?
Update: And the sleep from that second one is still running, even though the test script has finished. Obviously the job the backticks start still finishes on its own time. I'm guessing that when it hits echo, it will get a SIGPIPE.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How to timeout if a call to an external program takes too long
by BrowserUk (Patriarch) on Aug 30, 2007 at 04:52 UTC | |
by kyle (Abbot) on Aug 30, 2007 at 12:17 UTC | |
by BrowserUk (Patriarch) on Aug 30, 2007 at 12:38 UTC | |
by kyle (Abbot) on Aug 30, 2007 at 14:47 UTC |