Is there any way of enforcing a timeout on MailMsg? (And also MailFile?)

The general way to implement a "time-out" is to install an ALRM signal handler, then set the alarm function with alarm(NumOfSeconds).

$SIG{ALRM} = sub {print "oh darn, timeout!; die "timeout";} alarm(10); #10 second "countdown" somefunction(); alarm(0); #disables alarm # only get here if less than 10 seconds elapsed # during somefunction()
There are a WHOLE mess of caveats and "yeah but's" with alarms. So this is a complex subject! One common problem on Windows is that sleep() is implemented in terms of ALRM and this can cause some weird side-effects. But I assume that you are on Unix.

Perl >= 7.3 implements what are called "safe" or deferred signals which means that it doesn't handle them right away by default. Good news is that the Perl program can continue after an ALRM like this. Bad news is that in some cases the alarm signal might not be delivered.

Read this: cpan: Deferred Signals.
also, Perl doc alarm

I am sure that other Monks will suggest other references.
Try a normal "safe" mode alarm first using an eval block. That will allow your program to continue operation and try the function again. If that doesn't work and you need "non-safe" mode operation, then you must do as little as possible and exit() as soon as possible after the alarm because a low level non-reentrant OS function may have been interrupted.


In reply to Re: Race condition with Mail::Sender::MailMsg? by Marshall
in thread Race condition with Mail::Sender::MailMsg? by DrewP

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.