Threaded alternatives to smtplib?

Diez B. Roggisch deets at nospam.web.de
Mon May 4 02:45:17 EDT 2009


Alex Jurkiewicz schrieb:
> Hi all,
> I'm writing a Python script to do a "mail merge" style email 
> distribution. I create a few python threads and in each one I call 
> `smtpserver = smtplib.SMTP(our.smtpserver.com)`. However, during the 
> sending process, there seems to be only one connection open to our mail 
> server at any one time. In other words, all these threads gain me no 
> speed benefit at all!
> 
> I seem to be running into the issue where smtplib is not fully 
> thread-safe, as mentioned in this thread:
> http://mail.python.org/pipermail/python-list/2007-March/429067.html
> http://mail.python.org/pipermail/python-list/2007-March/429172.html
> 
> Does anyone have suggestions as to a suitable workaround for this issue? 
> I was looking at the Twisted library, which seems possible but 
> significantly more complex.

I doubt that there is such issue. The above discussion is not concluding 
that there actually *are* threading-issues within smtplib. And looking 
at the source of smtplib, it certainly doesn't use any 
locking-primitives or (directly) any c-extension that might explain such 
behavior.

Without more code, it's impossible to tell if there is anything peculiar 
in your usage of the lib. Maybe you close your connections to fast to 
see several open?

Diez



More information about the Python-list mailing list