GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ThreadSanitizer: data race in _struct module initialization with InterpreterPoolExecutor (free-threading build) · Issue #140260 · python/cpython

ThreadSanitizer: data race in _struct module initialization with InterpreterPoolExecutor (free-threading build) #140260

New issue
Copy link
New issue
Copy link
Closed
Closed
ThreadSanitizer: data race in _struct module initialization with InterpreterPoolExecutor (free-threading build)#140260
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ashm-dev
ashm-dev
opened on Oct 17, 2025
Issue body actions

Bug report

Bug description:

ThreadSanitizer detects a data race when using InterpreterPoolExecutor with the free-threading build. Multiple threads simultaneously write to the global variable lilendian_table in the _struct module during module initialization.

The race occurs at:

  • Thread T1 and T2: Both write to lilendian_table at _structmodule_exec (lines 2745:31 and 2746:33)
  • Location: global 'lilendian_table' of size 840 at 0x7ffff4513ca0 in _struct.cpython-315td-x86_64-linux-gnu.so

Both threads are executing through InterpreterPoolExecutor, importing modules in separate subinterpreters, which triggers concurrent initialization of the _struct extension module.

How to Reproduce

Build configuration:

CC=clang CXX=clang++ ./configure --with-thread-sanitizer --with-pydebug --enable-experimental-jit=yes --with-lto=full --with-tail-call-interp --disable-gil
make -j

Run command:

TSAN_OPTIONS=handle_segv=0 ./python -X dev -X showrefcount bug.py

Test script (bug.py):

from concurrent.futures import InterpreterPoolExecutor
from functools import lru_cache

@lru_cache(maxsize=512)
def fib(n):
    """Function that JIT will compile"""
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)

if __name__ == '__main__':
    with InterpreterPoolExecutor() as t:
        for i in range(2):
            t.submit(fib, i)

Note: The race occurs with any loop iteration count (range(1), range(2), etc.)

TSAN Output

log.txt

Environment

  • CPython version: main branch
  • Operating System: Linux
  • Compiler: Clang
  • Build flags: --with-thread-sanitizer --with-pydebug --enable-experimental-jit=yes --with-lto=full --with-tail-call-interp --disable-gil

Additional Information

A second similar data race is also reported for another write in _structmodule_exec at line 2746:33 to the same global variable.

Both races involve InterpreterPoolExecutor threads executing module initialization code concurrently in different subinterpreters.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-140260: Fix data race in _struct module initialization with subinterpreters #140909
  • [3.14] gh-140260: fix data race in _struct module initialization with subinterpreters (GH-140909) #141501

Activity

  1. ashm-dev
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 17, 2025
  2. colesbury
    added
    topic-subinterpreters
    on Oct 17, 2025
  3. github-project-automation
    added this to Subinterpreterson Oct 17, 2025
  4. github-project-automation
    moved this to Todo in Subinterpreterson Oct 17, 2025
  5. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Oct 18, 2025
  6. kumaraditya303
    added a commit that references this issue on Nov 13, 2025

    gh-140260: fix data race in `_struct` module initialization with subi…

    63548b3
  7. miss-islington
    added a commit that references this issue on Nov 13, 2025

    pythongh-140260: fix data race in `_struct` module initialization wit…

    a154c08
  8. kumaraditya303
    added a commit that references this issue on Nov 13, 2025

    [3.14] gh-140260: fix data race in `_struct` module initialization wi…

    79195df
  9. kumaraditya303
    closed this as completedon Nov 13, 2025
  10. github-project-automation
    moved this from Todo to Done in Subinterpreterson Nov 13, 2025
  11. CuriousLearner
    added 3 commits that reference this issue on Nov 13, 2025

    Merge branch 'main' into fix-issue21914

    b9f473c

    Merge branch 'main' of github.com:python/cpython into fix-Issue18387

    c46ecc5

    Merge branch 'main' of github.com:python/cpython into fix-issue24255

    c240289
  12. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-140260: fix data race in `_struct` module initialization wit…

    1ce571b
  13. serhiy-storchaka
    added this to Struct, memoryview and array issues 🏗️on Jul 13, 2026
  14. github-project-automation
    moved this from Todo to Done in Struct, memoryview and array issues 🏗️on Jul 13, 2026
  15. github-project-automation
    moved this to Todo in Struct, memoryview and array issues 🏗️on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Subinterpreters
      Status
      Done
      Show more project fields
    • Struct, memoryview and array issues 🏗️
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.