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 — SIGSEGV with generators in free-threaded build · Issue #120321 · python/cpython

SIGSEGV with generators in free-threaded build #120321

New issue
Copy link
New issue
Copy link
Closed
Closed
SIGSEGV with generators in free-threaded build#120321
Copy link
Labels
3.15bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Description

@rostan-t
rostan-t
opened on Jun 10, 2024
Issue body actions

Crash report

What happened?

Trying to iterate on a generator from multiple threads under the free-threaded build results in a segmentation fault.

Here is a minimal repro:

import concurrent.futures


def gen():
    while True:
        yield


it = gen()
with concurrent.futures.ThreadPoolExecutor() as executor:
    while True:
        _ = executor.submit(lambda: next(it))

The issue seems to be specific to generators as other kinds of iterators work well in parallel.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

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

Python 3.14.0a0 experimental free-threading build (heads/main:c3b6dbff2c, Jun 10 2024, 16:54:16) [GCC 11.4.0]

Linked PRs

  • gh-120321: Lock gen_send #120327
  • gh-120321: Make gi_frame_state transitions atomic in FT build #142599
  • gh-120321: Fix TSan reported race in gen_clear_frame #142995
  • gh-120321: Avoid -Wunreachable-code warning on Clang #143022
  • gh-120321: Make gen.gi_frame.clear() thread-safe #143112
  • gh-120321: Fix TSan reported races on gi_frame_state #143128
  • gh-120321: Add missing "return false" in gen_try_set_executing #144291
  • gh-120321: Make gi_yieldfrom thread-safe in free-threading build #144292
  • gh-120321: Add gi_state, cr_state, and ag_state attributes #144409
  • gh-120321: fix thread safety of concurrently iterating over async generators #155025
Reacted by Michał Szołucha and Yongtao Huang

Activity

Next
  1. rostan-t
    added
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Jun 10, 2024
  2. Fidget-Spinner commented on Jun 10, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Jun 10, 2024
    Member
    More actions

    Thanks for the repro. Looking into this.

  3. Fidget-Spinner
    self-assigned this
    on Jun 10, 2024
  4. Fidget-Spinner
    added
    topic-free-threading
    on Jun 10, 2024
  5. Fidget-Spinner commented on Jun 10, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Jun 10, 2024
    Member
    More actions

    Confirmed, with pydebug and tsan.

  6. Zheaoli commented on Jun 10, 2024

    @Zheaoli
    Zheaoli
    on Jun 10, 2024
    Contributor
    More actions

    May I take a chance to dive into this issue?

  7. Fidget-Spinner commented on Jun 10, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Jun 10, 2024
    Member
    More actions

    @Zheaoli sorry I assigned myself on this one I have a fix already and will put it up shortly. Do you have any specific issues in mind you would like to work on? I could help mentor/guide you on stuff you're interested in if I can help!

  8. Zheaoli commented on Jun 10, 2024

    @Zheaoli
    Zheaoli
    on Jun 10, 2024
    Contributor
    More actions

    sorry I assigned myself on this one I have a fix already and will put it up shortly

    No problem!

    Do you have any specific issues in mind you would like to work on? I could help mentor/guide you on stuff you're interested in if I can help!

    For now, I'm a fresh man try to be more familiar with the CPython codebase.

    I'm now working on #104280 to make dtrace more functional to help debug the process. I'm also interested in JIT and Tier2(especially to enhance the observerability for the Python process). But I'm still trying to find the issue I can fix and the thing I can do(lol

    Thanks for knowing that you will be willing to mentor/guide me lol!

  9. Fidget-Spinner commented on Jun 11, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Jun 11, 2024
    Member
    More actions

    @Zheaoli please send me an email I'll help give some pointers privately

  10. Fidget-Spinner
    removed their assignment
    on Nov 15, 2024
  11. colesbury
    added a commit that references this issue on Mar 13, 2025

    pythongh-120321: Use atomics for PyGenObject.gi_frame_state

    b67dc73
  12. colesbury
    added 2 commits that reference this issue on Mar 27, 2025

    pythongh-120321: Use atomics for PyGenObject.gi_frame_state

    a6e0872

    pythongh-120321: Use atomics for PyGenObject.gi_frame_state

    6f50a92
  13. devdanzin commented on Apr 21, 2025

    @devdanzin
    devdanzin
    on Apr 21, 2025
    Member
    More actions

    fusil has hit this one during fuzzing, it results in different segfaults and an abort, here's the MRE I got:

    from threading import Thread
    
    gen = (x for x in range(1_000_000))
    def run_gen():
        for n in gen:
            pass
    
    [Thread(target=run_gen, args=()).start() for x in range(20)]
    Reacted by Mikhail Efimov
  14. kumaraditya303
    marked Generator already executing free-threaded crashes #135325 as a duplicate of this issue on Jun 10, 2025
  15. 37 remaining items

  16. colesbury
    added a commit that references this issue on Feb 3, 2026

    gh-120321: Add gi_state, cr_state, and ag_state attributes (gh-144409)

    7e2c9bd
  17. thunder-coding
    added 4 commits that reference this issue on Feb 15, 2026

    pythongh-120321: Make gen.gi_frame.clear() thread-safe (pythongh-143112)

    10f8d7e

    pythongh-120321: Add missing "return false" in gen_try_set_executing (p…

    f835c0b

    pythongh-120321: Make gi_yieldfrom thread-safe in free-threading build (

    f265600

    pythongh-120321: Add gi_state, cr_state, and ag_state attributes (pyt…

    802f326
  18. sergey-miryanov commented on May 4, 2026

    @sergey-miryanov
    sergey-miryanov
    on May 4, 2026
    Contributor
    More actions

    This fails with asserts on current 3.14:

    Assertion failed: frame == &entry.frame, file X:\Work\cpython\3.14\Python\generated_cases.c.h, line 7694
    

    And works well on current main.

    Should we close this now since it's not planned for backport?

  19. kumaraditya303
    closed this as completedon Jul 23, 2026
  20. kumaraditya303
    added
    3.15bugs and security fixesbugs and security fixes
    on Jul 23, 2026
  21. kumaraditya303 commented on Aug 1, 2026

    @kumaraditya303
    kumaraditya303
    on Aug 1, 2026
    Contributor
    More actions

    Reopening for async generators which are still not thread safe.

  22. kumaraditya303
    reopened this on Aug 1, 2026
  23. kumaraditya303
    added a commit that references this issue on Aug 19, 2026

    gh-120321: fix thread safety of concurrently iterating over async gen…

    61818b6
  24. kumaraditya303
    closed this as completedon Aug 19, 2026
  25. kumaraditya303
    added 3 commits that reference this issue on Aug 19, 2026

    pythongh-120321: Make gi_frame, cr_frame and ag_frame thread-safe in …

    fce51ab

    pythongh-120321: Make gi_frame, cr_frame and ag_frame thread-safe in …

    c7f9056

    pythongh-120321: Fix thread safety of gi_frame, cr_frame and ag_frame…

    ab95f29
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 fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

    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.