Skip to content

Crash when inspecting frame of other thread in free-threaded build #118680

Closed

Description

@chgnrdv

Crash report

What happened?

Found when playing with #118415 (comment). Appears on both debug and non-debug builds.

import sys
import threading

l = threading._PyRLock()

def f():
    while True:
        with l:
            pass

t = threading.Thread(target=f)
t.start()
while True:
    f = sys._current_frames()[t.ident]
    while f:
        f.f_code
        f = f.f_back

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0a6+ (heads/main:9fd33af5ac, May 7 2024, 03:18:30) [GCC 10.2.1 20210110]

Activity

  1. added
    type-crash
    on May 7, 2024
  2. savannahostrowski commented on May 7, 2024

    @savannahostrowski
    Member

    I can't reproduce the crash on a Mac (M3 Pro), in case that's helpful!

  3. erlend-aasland commented on May 7, 2024

    @erlend-aasland
    Contributor

    I can repro on a MacBook Pro (M1), using ./configure --disable-gil --with-pydebug && make:

    $ ./python.exe ./crash.py
    Assertion failed: (frame->frame_obj == NULL), function _PyFrame_MakeAndSetFrameObject, file frame.c, line 48.
    [1]    27564 abort      ./python.exe ./crash.py
    $ ./python.exe -VV
    Python 3.13.0a6+ (heads/main-dirty:d3c7821335, May  7 2024, 09:27:50) [Clang 15.0.0 (clang-1500.3.9.4)]
    $ ./python.exe -c "import sys; print(sys._is_gil_enabled())"
    False
  4. colesbury commented on May 7, 2024

    @colesbury
    Contributor

    Yeah, this function is not thread-safe. We need to figure out what to do about it.

    More precisely, the call sys._current_frames() is okay, but accessing other thread's frames while they are running is not thread-safe without the GIL.

  5. colesbury commented on Nov 26, 2025

    @colesbury
    Contributor
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

    topic-free-threadingtype-crash

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions