non-blocking communication with imaplib

I

Igor V. Rafienko

Hi,


I was wondering if anyone had a suggestion for the following issue. I
would like to talk to an IMAP-server, imaplib being the tool of
choice, of course. Unfortunately it may happen that the IMAP-server
fails to respond to certain commands, and I would like to be able to
detect that within a given time period (on the scale of 5-10 seconds).

Initially, I thought about playing with setsockblocking() for the
communication socket in the imaplib.IMAP4 object. However, the IMAP4
object uses a file object ("created from" the said socket), and the
underlying socket must be blocking according to [1].

Is there another option for detecting when the server fails to reply
within a given time slot? Could I perhaps temporarily set the socket
to non-blocking mode? Or maybe I am attacking this problem the wrong
way altogether?

Any hints would be greatly appreciated.

TIA,





ivr
[1] <http://docs.python.org/lib/socket-objects.html#l2h-3693>
 
L

Lawrence D'Oliveiro

I would like to talk to an IMAP-server, imaplib being the tool of
choice, of course. Unfortunately it may happen that the IMAP-server
fails to respond to certain commands, and I would like to be able to
detect that within a given time period (on the scale of 5-10 seconds).

Initially, I thought about playing with setsockblocking() for the
communication socket in the imaplib.IMAP4 object. However, the IMAP4
object uses a file object ("created from" the said socket), and the
underlying socket must be blocking according to [1].

[1] <http://docs.python.org/lib/socket-objects.html#l2h-3693>

According to the documentation
<http://docs.python.org/lib/imap4-objects.html>, you can override
the "read" and "readline" methods. How about replacing them with routines
that use select.select on the socket() object to implement a timeout?
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top