I have the following snippet of code. I make a DBI connection and after which sleep does not 'sleep'. Attached is my code
use DBI; while (1) { # never ending loop my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); $mon++; + $year+=1900; $now = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); print "Time before sleep $now\n"; sleep 30; print "Time after sleep $now\n"; $dbh = ();# Initializing the dbi variables $dbh = DBI->connect("DBI:Oracle:DEMODB", "DEMO" , "DEMO", { PrintError => 0 } ) or die "Unable to connect to DB $DB $!"; $dbh->disconnect or die; }
Attached is the output
Time before sleep 09/14/2007 13:21:08 Time after sleep 09/14/2007 13:21:08 Time before sleep 09/14/2007 13:21:38 Time after sleep 09/14/2007 13:21:38 Time before sleep 09/14/2007 13:21:38 Time after sleep 09/14/2007 13:21:38 Time before sleep 09/14/2007 13:21:38 Time after sleep 09/14/2007 13:21:38 Time before sleep 09/14/2007 13:21:38 Time after sleep 09/14/2007 13:21:38 Time before sleep 09/14/2007 13:21:39 Time after sleep 09/14/2007 13:21:39 Time before sleep 09/14/2007 13:21:39 Time after sleep 09/14/2007 13:21:39 Time before sleep 09/14/2007 13:21:39 Time after sleep 09/14/2007 13:21:39 Time before sleep 09/14/2007 13:21:39 Time after sleep 09/14/2007 13:21:39 Time before sleep 09/14/2007 13:21:39 Time after sleep 09/14/2007 13:21:39
So the first sleep works just fine but subsequent sleeps dont really sleep. Please help. Thanks I added an additional sleep clause after the first sleep and that seems to do the trick. So the first sleep fails the second one works. Blow is the new code -- Thanks ikegami
while (1) { # never ending loop my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); $mon++; + $year+=1900; $now = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); print "Time before 1st sleep $now\n"; sleep 30; $now = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); print "Time after 1st sleep $now\n"; $now = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); # new sleep added BELOW print "Time before 2nd sleep $now\n"; sleep 30; $now = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); print "Time after 2nd sleep $now\n"; $dbh = ();# Initializing the dbi variables $dbh = DBI->connect("DBI:Oracle:DEMODB", "DEMO" , "DEMO", { PrintError => 0 } ) or die "Unable to connect to DB $DB $!"; $dbh->disconnect or die; }

In reply to DBI messes up sleep by perljunky

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.