Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When using (from <a href="http://forums.mysql.com/read.php?51,256433,256478" rel="nofollow">MySQL forum</a>)</p> <pre><code>use Sys::SigAction qw( set_sig_handler ); eval { my $hsig = set_sig_handler( 'ALRM', sub { my $canceled = 1; die; }, { mask=&gt;[ qw( INT ALRM ) ] ,safe =&gt; 0 } ); alarm($timeout); ... alarm(0); } </code></pre> <p>I noticed that any subsequent calls made to <code>sleep($delay)</code> with <code>$timeout</code> shorter than <code>$delay</code> would end up with the script execution being terminated, and the print of "<code>Alarm clock</code>".</p> <p>The workaround I've found is to call <code>alarm()</code> again but with an improbably large value (3600), and cancel that alarm right after.</p> <pre><code>eval { alarm(3600); print " .... Meeeep ...."; # Some trace alarm(0); }; </code></pre> <p>Then I can use <code>sleep()</code> with no interference anymore.</p> <p>Example below (live code snippet):</p> <pre><code>sub unmesswithsleep { eval { alarm(3600); &amp;tracing (8, " .... Meeeep ...."); alarm(0); }; } sub lockDBTables { return (0) unless ($isdbMySQLconnect); my $stm = qq { LOCK TABLES myBIGtable WRITE }; my $timeout = 60; # This is the timer set to protect against deadlocks. Bail out then. eval { my $h = set_sig_handler( 'ALRM', sub { my $canceled = 1; die; }, { mask=&gt;[ qw( INT ALRM ) ] ,safe =&gt; 0 } ); alarm($timeout); my $res = $dbmyh-&gt;do($stm) + 0; alarm(0); # Reset alarm }; if ( $@ =~ m/Die/i ) { $isdbTabledlocked = 0; &amp;tracerr (0, "FATAL: Lock on Tables has NOT been acquired within ${timeout}s. Lock is set to &lt;$isdbTabledlocked&gt;."); &amp;unmesswithsleep(); # MUST be called each time alarm() is used return (0); } else { $isdbTabledlocked = 1; &amp;tracing (2, " Good: Lock on Tables has been acquired in time. Lock is set to &lt;$isdbTabledlocked&gt;."); &amp;unmesswithsleep(); # MUST be called each time alarm() is used return (1); } # Can use sleep() now. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload