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 — `Py_IsInitialized()` can return 1 before `Py_InitializeEx()` has completed. · Issue #146302 · python/cpython

Py_IsInitialized() can return 1 before Py_InitializeEx() has completed. #146302

New issue
Copy link
New issue
Copy link
Closed
#146303
Closed
Py_IsInitialized() can return 1 before Py_InitializeEx() has completed.#146302
#146303
Copy link
Assignees
gpshead
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@gpshead
gpshead
opened on Mar 22, 2026
Issue body actions

Bug report

Bug description:

The race condition is more easily noticed if site.py takes a while to execute as the internal "initialized" flag is set to 1 before the site import.

Example impact? PyO3 has to jump through some hoops to avoid problems here in embedding scenarios where multiple threads all want to use an interpreter (most often test suites, resulting in some flaky tests). PyO3/pyo3#5903

We document Py_IsInitialized() as safe to call at any time and as being accurate. It is technically safe, but it isn't currently accurate.

CPython versions tested on:

3.13, 3.14, 3.15-alpha

Linked PRs

  • gh-146302: make Py_IsInitialized() thread-safe and reflect true init completion #146303

Activity

  1. gpshead
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-C-API
    on Mar 22, 2026
  2. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 22, 2026
  3. gpshead
    added 2 commits that reference this issue on Mar 22, 2026

    pythongh-146302: make Py_IsInitialized() thread-safe and reflect true…

    1eda370

    Add regression test: Py_IsInitialized() must be false during site import

    59f51a2
  4. gpshead
    self-assigned this
    on Mar 22, 2026
  5. gpshead
    added 2 commits that reference this issue on Apr 11, 2026

    Merge branch 'main' into pythongh-146302-py-isinitialized-thread-safe

    aec5131

    gh-146302: make Py_IsInitialized() thread-safe and reflect true init …

    64afa94
  6. gpshead
    closed this as completedin #146303on Apr 11, 2026
  7. gpshead commented on Apr 12, 2026

    @gpshead
    gpshead
    on Apr 12, 2026
    MemberAuthor
    More actions

    not backporting based on this conversation: #146303 (comment)

  8. gpshead
    added
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Apr 12, 2026
  9. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146302: make Py_IsInitialized() thread-safe and reflect true…

    b58e57e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gpshead
    gpshead

Labels

3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    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.