[New-bugs-announce] [issue35276] Document thread safety

STINNER Victor report at bugs.python.org
Mon Nov 19 06:50:08 EST 2018

New submission from STINNER Victor <vstinner at redhat.com>:

Many developers only discover that a Python function/module is not thread safe because they have a bug in production...

Some examples:

* bpo-7672: ssl
* bpo-8865: select.poll is not thread safe
* bpo-539175, bpo-21216: socket.gethostbyname()
* bpo-7980: time.strptime()
* bpo-6647: warnings.catch_warnings()
* bpo-11077, bpo-33479: Tkinter
* bpo-1336, bpo-19809: subprocess on Python 2
* bpo-15329: deque
* bpo-35275: os.umask()

Hopefully, sometimes it was possible to fix it:

* bpo-3139: bytearray, buffer protocol
* bpo-28969: @functools.lru_cache
* bpo-21291: subprocess.Popen.wait()

In the asyncio documentation, I explicitly documented that, by design, most classes are not thread-safe. For example, asyncio.Lock() is *NOT* thread-safe:

Maybe we should start to use a standard way to describe "thread safety". See "POSIX Safety Concepts" of the GNU libc:


Example with setlocale, "MT-Unsafe":



My own (incomplete) list of "process-wide states":

assignee: docs at python
components: Documentation
messages: 330093
nosy: docs at python, vstinner
priority: normal
severity: normal
status: open
title: Document thread safety
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list