Ways to do timeouts in Perl?

前端 未结 3 715
滥情空心
滥情空心 2020-12-03 05:14

I frequently use the following pattern to set an upper bound to the running time of a particular code fragment in Perl:

my $TIMEOUT_IN_SECONDS = 5;
eval {
           


        
3条回答
  •  甜味超标
    2020-12-03 05:49

    You probably want to look at Sys::SigAction. I haven't used it myself, but it has some glowing reviews.

    One thing to watch out for is if "stuff that might timeout" uses sleep or alarm itself. Also, in the error handling code, I assume you're prepared for errors other than a timeout.

提交回复
热议问题