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

Hello, After reading Using Signal Handlers and using the worker MPM, how do I timeout the following:
I am working with the module Net::RabbitMQ.
use Net::RabbitMQ; my $mq = Net::RabbitMQ->new(); # ... # this waits, how do I time it out, say 30s my $frame = $mq->recv();
How do interrupt this operation cleanly?

Thank you

Replies are listed 'Best First'.
Re: mod_perl2 | rabbitMQ | alarm
by sflitman (Hermit) on Mar 26, 2010 at 19:31 UTC
    You could try

    1) Use the alarm function to raise a signal after a number of seconds

    eval { local $SIG{ALRM}=sub { die "ALARM\n" }; # \n is required alarm 300; # give it 5 minutes # your code here alarm 0; # reset alarm }; if ($@ eq "ALARM\n") { print "Timed out!\n"; }

    2) Use Apache TimeOut directive

    3) Use Time::Out, it looks cool and is well-documented.

    Hope that helps,
    SSF

      Hi,

      thanks for your reply. if I read the docs on threaded mpms and Time::Out correctly:

      1) is not possible

      2) I need to finish the request

      3) is based on alarm

      Thanks