Is python is fully thread safe

Donn Cave donn at
Sun Jul 25 06:17:22 CEST 2004

Quoth Franois Pinard <pinard at>:
| Well, bugs occurring out of lack of thread-safety might, in many
| circumstances, hide for long before popping out, and hide again for long
| afterwards.  They are not easy to reproduce.  "Testing reveals presence
| of bugs, not their absence", as a proverb, is especially true in the
| context of thread-safety.
| Unless I'm missing a point (which is very possible), it does not seem
| to me that Python documentation is especially collaborative at teaching
| where threads are safe or not to use, so I'm left with the unpleasant
| feeling that my threaded Python applications should (ideally) never be
| allowed to go in real production.  It's OK if I'm the only one to suffer
| from unexpected problems.
| I would much like if Python documentation had more definite and
| definitive answers about thread-safety of Python, everywhere.

Well, I too am skeptical about multithreaded programs in production -
written in Python or anything else.  That is not to say it can't work,
but concurrency is just fraught with potential for trouble.  I don't
imagine that's going to stop people from using them, but they really
need to be able to think somewhat analytically about the issues.
I think you understand that it's a little more complex than "Hot dog,
the documentation says Python is thread safe!"

Ironically, Python is actually a little ahead here because it doesn't
strictly speaking support concurrency.  That makes Python internals
effectively the same as thread safe, so thread safety issues would be
confined to application level issues and external functions that run
after releasing the interpreter lock.  I've had no particular trouble
in my programs using a multithreaded API where others reportedly did
have trouble, and for all I know it may be just because I was using
Python and they weren't.

	Donn Cave, donn at

More information about the Python-list mailing list