Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found