I don't know why it's happening, but localizing the alarm handler in Enginesub.pm seems to solve it over here.

sub go { my $self = shift @_; local $SIG{ALRM} = \&ti; eval { ...

Output:

5 seconds main input: no input running.... name name1 (2 seconds) sub input: no input running defaults..... name name2 (2 seconds) sub input: no input running defaults..... 5 seconds main input: no input running.... name name1 (2 seconds) sub input: no input running defaults..... name name2 (2 seconds) sub input: no input running defaults.....

Update: Aha, of course... Since you don't localize the handler in Enginesub, it will replace the one you had for your main loop. This means that the second time the 5 second timeout triggers, it will call the ti sub instead of the timed_out sub. This in turn means that your if ($@ =~ /BLAH/) is false, since ti sets it to TIMEOUT instead.

Changing your main while loop to:

while() { eval { alarm(5); print "\n\n5 seconds main input: "; chomp(my $input = <STDIN>); alarm(0); }; if ($@ =~ /BLAH/) { print "\n\nno input running....\n\n"; $engine->run(); } if ($@ =~ /TIMEOUT/) { print "\n\nOops, still using ti handler...\n\n"; } sub timed_out { die "BLAH"; } }

The output is:

5 seconds main input: no input running.... name name1 (2 seconds) sub input: no input running defaults..... name name2 (2 seconds) sub input: no input running defaults..... Oops, still using ti handler... 5 seconds main input: Oops, still using ti handler... 5 seconds main input: Oops, still using ti handler...

(Removed some line breaks to make things easier to read)


In reply to Re: Perl OO, input alarm timeout by Crackers2
in thread Perl OO, input alarm timeout by yoda54

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.