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 — profiling.sampling may cause `assert!(has_gil && gil_requested)` to fail · Issue #142207 · python/cpython

profiling.sampling may cause assert!(has_gil && gil_requested) to fail #142207

New issue
Copy link
New issue
Copy link
Closed
Closed
profiling.sampling may cause assert!(has_gil && gil_requested) to fail#142207
Copy link
Labels
3.15bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@yihong0618
yihong0618
opened on Dec 3, 2025
Issue body actions

Bug report

Bug description:

./configure --with-pydebug
make -j8
./python -m profiling.sampling run --live -i 1 -d 100000 -a -m test  
# waiting but not 100% reproducer
Image

easy way reproducer

diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index f6ada3892f8..a5b1290ac70 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -409,9 +409,9 @@ take_gil(PyThreadState *tstate)
         _PyThreadState_HangThread(tstate);
     }
     assert(_PyThreadState_CheckConsistency(tstate));
-
-    tstate->gil_requested = 0;
     tstate->holds_gil = 1;
+    for (volatile int _i = 0; _i < 10; _i++) {}  // Widen window
+    tstate->gil_requested = 0;
     _Py_unset_eval_breaker_bit(tstate, _PY_GIL_DROP_REQUEST_BIT);
     update_eval_breaker_for_thread(interp, tstate);
 

then its 100% reproduce

./python -m profiling.sampling run --live -i 1 -d 100000 -a -m test 

the fix:
seems because its remote we can not fix it in ceval_gil.c
and drop the assert way works in my side

diff --git a/Modules/_remote_debugging/threads.c b/Modules/_remote_debugging/threads.c
index 99147b01a1b..69a85761562 100644
--- a/Modules/_remote_debugging/threads.c
+++ b/Modules/_remote_debugging/threads.c
@@ -335,12 +335,9 @@ unwind_stack_for_thread(
 #endif
     if (has_gil) {
         status_flags |= THREAD_STATUS_HAS_GIL;
+        gil_requested = 0;
     }
 
-    // Assert that we never have both HAS_GIL and GIL_REQUESTED set at the same time
-    // This would indicate a race condition in the GIL state tracking
-    assert(!(has_gil && gil_requested));
-
     // Check CPU status
     long pthread_id = GET_MEMBER(long, ts, unwinder->debug_offsets.thread_state.thread_id);
 

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-142207: remove assertions incompatible under profiling.sampling #142331

Activity

  1. yihong0618
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 3, 2025
  2. cmaloney
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-profiling
    on Dec 3, 2025
  3. picnixz
    changed the title [-][3.15] profiling.sampling may cause assertssertion `!(has_gil && gil_requested)' failed.[/-] [+]profiling.sampling may cause `assert!(has_gil && gil_requested)` to fail[/+] on Dec 6, 2025
  4. picnixz
    added
    3.15bugs and security fixesbugs and security fixes
    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
    and removed
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Dec 6, 2025
  5. pablogsal
    added a commit that references this issue on Dec 8, 2025

    gh-142207: remove assertions incompatible under `profiling.sampling` (#…

    3db7bf2
  6. pablogsal
    closed this as completedon Dec 8, 2025
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

    3.15bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-profilingtype-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.