non-blocking communication with imaplib
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Mon Aug 27 07:40:19 EDT 2007
In message <xjv8x84dm33.fsf at oinn.ifi.uio.no>, Igor V. Rafienko wrote:
> 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?
More information about the Python-list
mailing list