[New-bugs-announce] [issue2132] Blocking sockets take entirely too long to timeout
report at bugs.python.org
Sun Feb 17 19:56:54 CET 2008
New submission from Nathan Duran:
The following code:
test = smtplib.SMTP('mail.host.com')
will hang the entire script for about ten minutes when run on a machine
which is connected to the internet via an ISP who blocks port 25 (which is
pretty much all of them these days). Closer inspection of the smtplib
sources reveals that it is making use of blocking sockets, which is all
well and good, but I do not believe they should be allowed to block for
such a ridiculously lengthy period of time.
My task is to walk the list of MX records provided by a DNS query, connect
to each server listed and check a user-supplied address for validity. If I
have to wait 10 minutes for an exception to be thrown for each
unresponsive server, this process could easily take hours per address,
which is completely unacceptable.
My workaround is to ditch smtplib entirely and write my own socket code,
but setting a timeout on a socket throws it into non-blocking mode, which
is not entirely what I want, either. PHP allows one to apply a perfectly
sane timeout to a blocking socket without any difficulty, and this is
something I'm frankly rather surprised to see Python choke on.
What I'd expect to see is an exception after less than a minute's worth of
repeated failures so the caller can catch it and try another port.
components: Library (Lib)
title: Blocking sockets take entirely too long to timeout
versions: Python 2.5
Tracker <report at bugs.python.org>
More information about the New-bugs-announce