This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author khiltd
Recipients khiltd
Date 2008-02-17.18:56:52
SpamBayes Score 0.008905268
Marked as misclassified No
Message-id <1203274614.89.0.5704894361.issue2132@psf.upfronthosting.co.za>
In-reply-to
Content
The following code:

import smtplib

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.
History
Date User Action Args
2008-02-17 18:56:55khiltdsetspambayes_score: 0.00890527 -> 0.008905268
recipients: + khiltd
2008-02-17 18:56:54khiltdsetspambayes_score: 0.00890527 -> 0.00890527
messageid: <1203274614.89.0.5704894361.issue2132@psf.upfronthosting.co.za>
2008-02-17 18:56:53khiltdlinkissue2132 messages
2008-02-17 18:56:52khiltdcreate