thread safe SMTP module
Aahz
aahz at pythoncraft.com
Sun Mar 4 14:00:33 EST 2007
In article <mailman.4644.1172997256.32031.python-list at python.org>,
Gordon Messmer <yinyang at eburg.com> wrote:
>Aahz wrote:
>>
>> That doesn't make any sense. Blocking I/O generally releases the GIL,
>> which is the whole reason Python doesn't totally suck for threading.
>
>Nevertheless, among the caveats listed at
>http://docs.python.org/lib/module-thread.html is:
>
>"Not all built-in functions that may block waiting for I/O allow other
>threads to run. (The most popular ones (time.sleep(), file.read(),
>select.select()) work as expected.)"
That's why I said "generally".
>> There may be other thread problems, but I doubt that you have correctly
>> analyzed their source.
>
>I subclassed smtplib.SMTP and replaced only the lines of code that had
>to do with blocking IO (connect, send and receive operations).
>Beforehand, python would occasionally lock up. Having made those
>changes, python stopped locking up. I think the problem was pretty well
>apparent. I can't pin it down to which one of those three operations
>was at fault, and it may be that only one was. However, when I use
>non-blocking IO, the application works. When I used smtplib.SMTP, it
>didn't.
>
>I'm open to other explanations.
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.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"I disrespectfully agree." --SJM
More information about the Python-list
mailing list