[Python-Dev] Re: Thread safety of deques

Michael Hudson mwh at python.net
Tue Jul 20 16:20:01 CEST 2004


"Moore, Paul" <Paul.Moore at atosorigin.com> writes:

> From: Aahz
>> On Mon, Jul 19, 2004, Phillip J. Eby wrote:
>>>
>>> However, anything that calls back into Python code isn't necessarily 
>>> atomic, and in general, almost anything can call back into Python code.
>>
>> Yup.
>
>>> For example, the seemingly harmless dictionary item assignment can call 
>>> back into Python for a custom type's __hash__ and __eq__ methods, so could 
>>> it be that a thread switch could actually occur during this statement:
>>> 
>>>     foo[bar] = baz
>>> 
>>> if 'bar' has such custom methods?  Maybe I'm wrong, and the GIL is still 
>>> held in such a case, but I'm not sure *how*.
>
>> No, it isn't.
>
> Hmm. I think that makes the point fairly well - thread safety is subtle, and
> not to be taken lightly. Whether that was Raymond's point or mine, I'm less
> sure :-)

To be fair, you don't need threads to tickle very odd behaviour here
-- check out vicious_descriptor_nonsense in test_descr or test_mutants
or some stuff in test_sort.  Threads just add that delicious air of
unpredictability to the mix :-)

Cheers,
mwh

-- 
  To summarise the summary of the summary:- people are a problem.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 12


More information about the Python-Dev mailing list