thread safe SMTP module

Gordon Messmer yinyang at eburg.com
Sun Mar 4 15:19:38 EST 2007


Aahz wrote:
> 
> Assuming you have correctly tracked down the problem area, I would call
> that a thread bug in Python.  But my experience is that you simply have
> run into a problem with the socket.  I would suggest that using
> socket.setdefaulttimeout() would work just as well.

I believe that solution, also would not work.  This note is included in 
the socket documentation, regarding "timeout mode":

http://docs.python.org/lib/socket-objects.html
"A consequence of this is that file objects returned by the makefile() 
method must only be used when the socket is in blocking mode; in timeout 
or non-blocking mode file operations that cannot be completed 
immediately will fail."

smtplib.SMTP uses file objects when reading SMTP responses.  If I used 
setdefaulttimeout(), then the socket would be in timeout mode and the 
above note would be applicable.

I am not at all above calling python's behavior a bug, except that it 
seemed like a known behavior given the note in the thread documentation 
regarding built-in functions that block on I/O.



More information about the Python-list mailing list