Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Audit all built-in modules for thread safety #116738

Open
@swtaarrs

Description

@swtaarrs

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 usingPy_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 toPyModule_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:

  1. UsePyMutex as the basic unit of locking.
  2. If you need to hold a lock for a longer period of time, especially across calls that may reenter Python code or acquire other locks, usecritical sections.
  3. If the module you're looking at is a thin wrapper around related code elsewhere in CPython (e.g.,Modules/_codecsmodule.c andPython/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.
  4. Remember that C API functions are generally expected to handle thread-safety internally. C code that operates on Python objects using only C API calls is usually thread-safe by default (but look out for code that reads or modifiesPyObject*s in C structs, since that needs synchronization).
  5. Watch out for functions/macros that return borrowed references, likePyList_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

  • Modules/_abc.c
  • Modules/arraymodule.c -gh-128942: make arraymodule.c free-thread safe (lock-free) #130771
  • Modules/_asynciomodule.c
  • Modules/atexitmodule.c
  • Modules/binascii.c
  • Modules/_bisectmodule.c
  • Modules/_blake2/blake2module.c
  • Modules/_bz2module.c
  • Modules/cjkcodecs/cjkcodecs.h
  • Modules/cjkcodecs/multibytecodec.c
  • Modules/cmathmodule.c
  • Modules/_codecsmodule.c
  • Modules/_collectionsmodule.c
  • Modules/_contextvarsmodule.c
  • Modules/_csv.c
  • Modules/_ctypes/_ctypes.c
  • Modules/_ctypes/_ctypes_test.c
  • Modules/_cursesmodule.c
  • Modules/_curses_panel.c
  • Modules/_datetimemodule.c
  • Modules/_dbmmodule.c
  • Modules/_decimal/_decimal.c
  • Modules/_elementtree.c
  • Modules/errnomodule.c
  • Modules/faulthandler.c
  • Modules/fcntlmodule.c
  • Modules/_functoolsmodule.c
  • Modules/gcmodule.c
  • Modules/_gdbmmodule.c
  • Modules/grpmodule.c
  • Modules/_hashopenssl.c
  • Modules/_heapqmodule.c
  • Modules/_io/_iomodule.c
  • Modules/itertoolsmodule.c
  • Modules/_json.c -gh-116738: Make _json module safe in the free-threading build #119438
  • Modules/_localemodule.c
  • Modules/_lsprof.c
  • Modules/_lzmamodule.c
  • Modules/mathmodule.c
  • Modules/md5module.c
  • Modules/mmapmodule.c
  • Modules/_multiprocessing/multiprocessing.c
  • Modules/_multiprocessing/posixshmem.c
  • Modules/_opcode.c
  • Modules/_operator.c
  • Modules/overlapped.c
  • Modules/_pickle.c
  • Modules/posixmodule.c
  • Modules/_posixsubprocess.c
  • Modules/pwdmodule.c
  • Modules/pyexpat.c
  • Modules/_queuemodule.c
  • Modules/_randommodule.c
  • Modules/readline.c
  • Modules/resource.c
  • Modules/_scproxy.c
  • Modules/selectmodule.c
  • Modules/sha1module.c
  • Modules/sha2module.c
  • Modules/sha3module.c
  • Modules/signalmodule.c
  • Modules/socketmodule.c
  • Modules/_sqlite/module.c
  • Modules/_sre/sre.c
  • Modules/_ssl.c
  • Modules/_stat.c
  • Modules/_statisticsmodule.c
  • Modules/_struct.c
  • Modules/_suggestions.c
  • Modules/symtablemodule.c
  • Modules/_sysconfig.c
  • Modules/syslogmodule.c
  • Modules/termios.c
  • Modules/_testbuffer.c
  • Modules/_testcapimodule.c
  • Modules/_testclinic.c
  • Modules/_testclinic_limited.c
  • Modules/_testexternalinspection.c
  • Modules/_testimportmultiple.c
  • Modules/_testinternalcapi.c
  • Modules/_testlimitedcapi.c
  • Modules/_testmultiphase.c
  • Modules/_testsinglephase.c
  • Modules/_threadmodule.c
  • Modules/timemodule.c
  • Modules/_tkinter.c
  • Modules/_tracemalloc.c
  • Modules/_typingmodule.c
  • Modules/unicodedata.c
  • Modules/_uuidmodule.c
  • Modules/_weakref.c
  • Modules/_winapi.c
  • Modules/_xxinterpchannelsmodule.c
  • Modules/_xxinterpqueuesmodule.c
  • Modules/xxlimited_35.c
  • Modules/xxlimited.c
  • Modules/xxmodule.c
  • Modules/_xxsubinterpretersmodule.c
  • Modules/xxsubtype.c
  • Modules/_xxtestfuzz/_xxtestfuzz.c
  • Modules/zlibmodule.c
  • Modules/_zoneinfo.c
  • Objects/genobject.c (including ag_running_async)
  • PC/msvcrtmodule.c
  • PC/python3dll.c
  • PC/winreg.c
  • PC/winsound.c
  • Python/bltinmodule.c
  • Python/import.c
  • Python/instrumentation.c
  • Python/marshal.c
  • Python/Python-ast.c
  • Python/Python-tokenize.c
  • Python/sysmodule.c
  • Python/_warnings.c
Completed Issues

Completed Issues

Has 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/, especiallythis section

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp