[Python-Dev] RE: The Python interpreter is not fully thread-safe.

Michael Chermside mcherm@mcherm.com
Tue, 10 Jun 2003 09:52:17 -0700


[Michael Chermside]
> Please note that what was confusing the the original poster was
> almost certainly the docs saying that "Python" was not thread-safe
> when what was really intended was, as Tim points out, that Python's
> C api was not thread safe. Using the term "free threading" is fine,
> but also make it clear that it's the _C api_ we're talking about,
> because Python itself (ie, programs coded in pure Python) _IS_
> threadsafe.

[Tim Peters]
> Not really, under most meanings of "thread safe".  For example,
> 
> """
> id = 0
> def getid():
>     global id
>     id += 1
>     return id
> """
> 
> wouldn't be considered a thread-safe way to get an id
      [...]
> Thread safety is a complicated topic
      [...]
> That's why I'd rather explain the situation than try to reduce it to
> buzzword compliance -- the buzzwords here don't have objective,
> app-independent, universally accepted meanings.

Well, you have a very good point here... just slapping the lable
"thread safe" onto it doesn't make the complexity go away. But I
still have a concern... the PHB (pointy haired boss) issue. If the
Python docs suggest that python is "not threadsafe", then the PHBs
of the world are going to say "you must use Java", since it obviously
IS threadsafe, whatever that means.

Now, I *refuse* to lower the level of discourse to that which a
PHB can comprehend. But it's worth a bit of care not to upset them.
Replacing "not threadsafe" with something equivalent to Raymond's:

   > Any library that *is* "fully thread-safe" establishes certain
   > conventions that users have to follow to achieve thread-safety. The
   > same is true for Python: if the conventions (which are elaborated in
   > section 8.1) are followed, Python is also fully thread-safe. It's just
   > that it does not support what is commonly called "free threading".

...should do admirably. It explains things for those who want to know,
but also has the key phrase "thread-safe" in it, which is all the PHB
cares about.

-- Michael Chermside

and also