You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by "Luiz Fernando B. Ribeiro" <li...@athome.pro.br> on 2002/02/19 20:48:13 UTC

eval {} die and $SIG{ALRM}

Hello,

  I'm having trouble with the common technique (alarm eval{}) to avoid
  blocking operations. The die message is always going to the browser
  even when trapped by the eval block.

eval {
     local $SIG{ALRM} = sub {die};
     alarm 3;
     open(FIFO,">$fifo");
     alarm 0;
};
if ($@) {
   debug("Cliente ausente...");
   close(FIFO);
} else {
  print FIFO ">TERM";
  close(FIFO);
}

  The alarm is being called and the debug message is print but in the
  browser I get the embperl message about the die:

  [1485]ERR: 24: Line 104: Error in Perl code: Died at ...

Any clues or wokarounds?

Thanks in advance.

Luiz Fernando B. Ribeiro


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: eval {} die and $SIG{ALRM}

Posted by "Luiz Fernando B. Ribeiro" <li...@athome.pro.br>.
Hi all,

  I have solved the problem using a module called Exception.pm, it
  provides a very good interface for exception handling and I was able
  to bypass the die bug not being trapped by the eval block.

Best wishes,

Luiz Fernando B. Ribeiro

use Exception qw(:all);

...

$fifo = "$pasta/$fifo";

# 5 segundo de timeout no fifo...
my $block = new Exception;
my $fifo_ok =
   try {
       $SIG{ALRM} = sub { $block->raise };
       alarm 5;
       open(FIFO, ">$fifo");
       alarm 0;
       return 1;
   } when $block, except {
       debug("FIFO $fifo está surdo...");
       return 0;
   };

if ($fifo_ok) {
   print FIFO $msg;
   close FIFO;
}

Resposta a sua mensagem de terça-feira, 19 de fevereiro de 2002:

LFBR> Hello,

LFBR>   I'm having trouble with the common technique (alarm eval{}) to avoid
LFBR>   blocking operations. The die message is always going to the browser
LFBR>   even when trapped by the eval block.

LFBR> eval {
LFBR>      local $SIG{ALRM} = sub {die};
LFBR>      alarm 3;
LFBR>      open(FIFO,">$fifo");
LFBR>      alarm 0;
LFBR> };
LFBR> if ($@) {
LFBR>    debug("Cliente ausente...");
LFBR>    close(FIFO);
LFBR> } else {
LFBR>   print FIFO ">TERM";
LFBR>   close(FIFO);
LFBR> }

LFBR>   The alarm is being called and the debug message is print but in the
LFBR>   browser I get the embperl message about the die:

LFBR>   [1485]ERR: 24: Line 104: Error in Perl code: Died at ...

LFBR> Any clues or wokarounds?

LFBR> Thanks in advance.

LFBR> Luiz Fernando B. Ribeiro


LFBR> ---------------------------------------------------------------------
LFBR> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
LFBR> For additional commands, e-mail: embperl-help@perl.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: eval {} die and $SIG{ALRM}

Posted by Angus Lees <gu...@switchonline.com.au>.
On Tue, Feb 19, 2002 at 04:48:13PM -0300, Luiz Fernando B. Ribeiro wrote:
>   I'm having trouble with the common technique (alarm eval{}) to avoid
>   blocking operations. The die message is always going to the browser
>   even when trapped by the eval block.
> 
> eval {

try adding:
       local $SIG{__DIE__} = undef;

>      local $SIG{ALRM} = sub {die};
>      alarm 3;
>      open(FIFO,">$fifo");
>      alarm 0;
> };
> 
>   The alarm is being called and the debug message is print but in the
>   browser I get the embperl message about the die:
> 
>   [1485]ERR: 24: Line 104: Error in Perl code: Died at ...
> 
> Any clues or wokarounds?

i'm just guessing here - i haven't done even the smallest amount of
experimentation.

-- 
 - Gus

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: eval {} die and $SIG{ALRM}

Posted by Kee Hinckley <na...@somewhere.com>.
At 7:47 AM +0100 2/20/02, Gerald Richter wrote:
>Hello,
>>
>>    I'm having trouble with the common technique (alarm eval{}) to avoid
>>    blocking operations. The die message is always going to the browser
>  >   even when trapped by the eval block.
>  >

I use die quite a bit in Embperl (often, but not always, wrapped with 
Error.pm's throw/try syntax and I haven't had any problems).  Does it 
work properly if you aren't doing alarm's?
-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
nazgul@somewhere.com

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: eval {} die and $SIG{ALRM}

Posted by Gerald Richter <ri...@ecos.de>.
Hello,
>
>   I'm having trouble with the common technique (alarm eval{}) to avoid
>   blocking operations. The die message is always going to the browser
>   even when trapped by the eval block.
>

I don't have an idea at the moment what's going wrong here. Embperl itself
doesn't sets $SIG{__DIE__}, but I think there were some problems with
mod_perl and alarms in the past and I am not quite sure if they still
exists. Could you try to run your test code from the command line (via
embpexec.pl). This will show if it's an mod_perl problem (in which case you
should search the mod_perl mailing list archives, I guess you will find
something there), or if it's an EMbperl problem, then I have to see what's
going wrong....

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org