sleep(30) hangs

M

marathoner

Hi,

I have a programs that checks emails via IMAP and then sleeps for 30
seconds. Occasionally, it hangs on the line where it calls sleep(30).

I use Perl 5.8.8 (ActivePerl Build 820) running on Windows 2000 SP4.

A simplified version of the code looks like this:


use Mail::IMAPClient;

$host = 'localhost';
$id = 'user';
$pass = 'pass';
$inbox = 'inbox';

while(1)
{
print scalar localtime, "\n";
$imap = Mail::IMAPClient->new(
Server => $host,
User => $id,
Password=> $pass,
Clear => 5,
Debug => 0,
Timeout => 30,
Uid => 0,

) or die "Cannot connect to $host as $id: $@";
print "Checking for new messages...\n";
$imap->select($inbox);

$m = $imap->message_count();
for $n (1..$m)
{
print $imap->get_header($n, 'To');

# more processing here
# .......

$imap->delete_message($n);
}

$imap->expunge();
$imap->disconnect();
print scalar localtime, "\n";
print "Done. See you in 30 seconds.\n\n\n";
sleep(30); # <-- this is where it hangs sometimes
print "waking up...\n\n";
}


Any input would be much appreciated.

Thank you.

Lei
 
T

Ted Zlatanov

On Tue, 18 Nov 2008 08:01:00 -0800 (PST) (e-mail address removed) wrote:

m> I have a programs that checks emails via IMAP and then sleeps for 30
m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
....
m> print "Done. See you in 30 seconds.\n\n\n";
m> sleep(30); # <-- this is where it hangs sometimes

sleep() may be interfering with other signal handlers. Try
system(sleep => 30) instead to run it as a shell command; does that make
a difference?

Ted
 
P

Peter J. Holzer

The reason is maybe that IMAP server need more time to logout user. I'm not
familiar with IMAP but my users which are using POP3 must leave 60 seconds time
space before he/she can login again.

How can this cause sleep to hang?

hp
 
P

Peter J. Holzer

[with activestate perl on Windows 2000]

m> I have a programs that checks emails via IMAP and then sleeps for 30
m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
...
m> print "Done. See you in 30 seconds.\n\n\n";
m> sleep(30); # <-- this is where it hangs sometimes

sleep() may be interfering with other signal handlers. Try
system(sleep => 30) instead to run it as a shell command; does that make
a difference?

Does Windows 2000 have a sleep command? Windows 2003 doesn't:

| Microsoft Windows [Version 5.2.3790]
| (C) Copyright 1985-2003 Microsoft Corp.
|
| C:\Dokumente und Einstellungen\hjp>sleep 30
| Der Befehl "sleep" ist entweder falsch geschrieben oder
| konnte nicht gefunden werden.

Translation: The command "sleep" is either misspelled or could not be
found.

hp
 
N

News123

Ted might be rigth.

I never looked at perl's implementation of sleep, but perhaps it's
implemented by settign an alarm and waiting for the alarm signal

If IMAP is messing around with signal handlers / alarms, then such
things might happen.

Perhaps you fall into a windows specific bug?

On unix I would propose to run your script with strace to check if
there's something weird to observe.

Does anybody know the Win2K equivalent of strace?

Perhaps this could give some ideas to Lei.



bye


N
 
N

News123

Just for info:


the perl script:
sleep(3)
sleep(3)


contained following in the strace output (linux):
time(NULL) = 1227450756
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({2, 0}, {2, 0}) = 0
time(NULL) = 1227450758
time(NULL) = 1227450758
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({3, 0}, {3, 0}) = 0
time(NULL) = 1227450761
 
T

Ted Zlatanov

PJH> [with activestate perl on Windows 2000]


m> I have a programs that checks emails via IMAP and then sleeps for 30
m> seconds. Occasionally, it hangs on the line where it calls sleep(30).m> print "Done. See you in 30 seconds.\n\n\n";
m> sleep(30); # <-- this is where it hangs sometimes
PJH> Does Windows 2000 have a sleep command? Windows 2003 doesn't:

PJH> | Microsoft Windows [Version 5.2.3790]
PJH> | (C) Copyright 1985-2003 Microsoft Corp.
PJH> |
PJH> | C:\Dokumente und Einstellungen\hjp>sleep 30
PJH> | Der Befehl "sleep" ist entweder falsch geschrieben oder
PJH> | konnte nicht gefunden werden.

PJH> Translation: The command "sleep" is either misspelled or could not be
PJH> found.

Sorry, I didn't realize this was a Windows setup. A Perl one-liner
would probably do it: system perl => -e => "sleep 30" (untested). I
don't know how sleep() works in Windows, so my suggestions may be
completely useless, but it's worth trying the simple stuff first before
doing in-depth debugging :)

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top