Is email package thread safe? (fwd)

Antoon Pardon apardon at forel.vub.ac.be
Thu Feb 10 03:11:21 EST 2005


Op 2005-02-09, Roman Suzi schreef <rnd at onego.ru>:
> On Wed, 9 Feb 2005, Antoon Pardon wrote:
>
>> Op 2005-02-09, Roman Suzi schreef <rnd at onego.ru>:
>>>
>>> Just to be sure, is email package of Python 2.3 thread-safe or not
>>> (to use, for example, in python-milter?)
>
>>> Can I assume that everything
>>> else without such notice is thread-safe?
>>
>> I doubt it. There is no indication that the email package uses any
>> kind of locking. So multiple thread working on the same message
>> will probably screw things up.
>
> Of course, I do not let threads to work on the same message!

Why should that be: "off course"? The random module you spoke about
was also only thread unsafe if you called the same random generator
from various threads. Using a randon generator per thread shouldn't
have been a problem. Since you mentioned that, I thought that was
the kind of thread safety you were after.

> I meant that the package doesn't pose other kinds of restrictions.
> Can it work in _any_ situation work on two different messages at the same 
> time, without any interference?

I can't give a guarantee, but there are no global statements and there
doesn't seem to be assignments to cross module variables I think it
would be a safe bet.

-- 
Antoon Pardon



More information about the Python-list mailing list