Repository navigation
Audit all built-in modules for thread safety #116738
Copy link
Copy link
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementextension-modulesC modules in the Modules dirC modules in the Modules dir
on Mar 13, 2024 - added a commit that references this issue
on Apr 11, 2024 - added a commit that references this issue
on May 2, 2024 @swtaarrs - Is it OK if I remove you as the owner?
Yep, I won't be doing any more work on this 😞
Reacted by mpage- added 4 commits that reference this issue
on Jun 5, 2024 150 remaining items
Load more actions- added a commit that references this issue
on Dec 8, 2025 - added a commit that references this issue
on Dec 15, 2025 - added a commit that references this issue
on Dec 18, 2025 - added a commit that references this issue
on Jan 13, 2026 - added a commit that references this issue
on Mar 7, 2026
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Proposal:
We should audit every built-in module for thread safety and make any necessary fixes. This can be done separately from tagging the modules as safe using
Py_mod_gil; any data races in built-in modules are considered bugs in the free-threaded build and not incompatibilities.Below is a list of all source files that contain at least one module definition, as defined by files that contain either a call to
PyModule_Create()or an array ofPyModuleDef_Slots. If you'd like to help out with this task, take a look at one of the incomplete files. If the conversion is trivial, check it off and attach the PR to this issue. Otherwise, convert the line into an issue and assign it to yourself.Every module is different, but here are a few high-level points to guide the work:
PyMutexas the basic unit of locking.Modules/_codecsmodule.candPython/codecs.c), you can also audit/convert the related non-module code. Otherwise, try to contain your work to just the module code, and create separate issues for any dependencies that aren't thread-safe.PyObject*s in C structs, since that needs synchronization).PyList_GetItem()orPyDict_GetItem(). If other threads could have references to the object, prefer functions likePyList_GetItemRef()orPyDict_GetItemRef()that return owned references (and will safely raise an error if the index/key doesn't exist).Files to audit
Completed Issues
Completed Issues
_warnings.cthread-safe in free-threaded build #116664_threadmodule.cthread-safe in--disable-gilbuilds #114271_structmodule thread-safe in--disable-gilbuilds #112062defaulttimeoutin free-threaded build #116616Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://peps.python.org/pep-0703/, especially this section
Linked PRs
_codecsmodule thread-safe #117530_csvmodule thread-safe (GH-118344) #125328dbm.gnumodule on FT Python build #138467cProfilemodule thread-safe (GH-138229) #138575resourcemodule on free-threading builds (GH-138504) #138793mmapmodule thread-safe (GH-139237) #139825dbm.gnumodule on FT Python build (GH-138467) #139987uuidmodule thread safety in free-threading (GH-140068) #140229contextvars.Contextthread safe #143074