Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a problem timing out a particular function call. Calls to Text::Unaccent::unac_string(), which is an XS binding to libiconv, hang on certain strings containing Russian and Asian text.

I would really like to avoid hacking at that module, so is there another way to make this timeout?

If not, what are some things in this function that could be causing my ALRM to be ignored?

Here's the snippet of code:
eval { local $SIG{ALRM} = sub { die "alarm timeout" }; local $SIG{__DIE__} = sub { alarm 0; die @_ }; alarm 2; print "calling"; # This prints out calling, and hangs forever, never printing "done +" $string = unac_string('UTF-8', $string); print "done"; alarm 0; };

Thanks

Replies are listed 'Best First'.
Re: SIGALRM timeout problem
by tilly (Archbishop) on Mar 27, 2004 at 08:36 UTC
    Odds are that you're using Perl 5.8, and are hitting the unfortunate side-effects of safe signal handling.

    Either Perl accepts signals immediately and sometimes will segfault. Or Perl only accepts them on the boundaries between opcodes and sometimes ignores them indefinitely.

    With 5.8.1 and later, you should be able get back the old behaviour by setting $ENV{PERL_SIGNALS} to "unsafe". (At least if I'm reading my local copy of perlrun properly, you can.)