Skip to content

Generator already executing free-threaded crashes #135325

Closed as duplicate of#120321
Closed as duplicate of#120321
@Dobatymo

Description

@Dobatymo

Crash report

What happened?

When running the following code snipped a few times, I can cause two different windows exceptions. And also the expected ValueError: generator already executing.

from threading import Thread

def inner(it):
    for _i in it:
        pass

def main():
    it = (i for i in range(100000))
    t1 = Thread(target=inner, args=(it,))
    t2 = Thread(target=inner, args=(it,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()

if __name__ == "__main__":
    main()
    print("success")
Assertion failed: (gen->gi_frame_state == FRAME_CREATED) || FRAME_STATE_SUSPENDED(gen->gi_frame_state), file ...\cpython\Objects\genobject.c, line 242
Windows fatal exception: code 0x80000003

<Cannot show all threads while the GIL is disabled>
Stack (most recent call first):
  File "...\t_iter.py", line 7 in inner
  File "...\cpython\Lib\threading.py", line 1016 in run
  File "...\cpython\Lib\threading.py", line 1074 in _bootstrap_inner
  File "...\cpython\Lib\threading.py", line 1036 in _bootstrap

Current thread's C stack trace (most recent call first):
  <cannot get C stack on this system>
Windows fatal exception: access violation

Assertion failed: frame->stackpointer != NULL, file ...\cpython\Include\internal\pycore_interpframe.h, line 173
<Cannot show all threads while the GIL is disabled>
Stack (most recent call first):
  File "...\t_iter.py", line 12 in <genexpr>
  File "...\t_iter.py", line 7 in inner
  File "...\cpython\Lib\threading.py", line 1016 in run
  File "...\cpython\Lib\threading.py", line 1074 in _bootstrap_inner
  File "...\cpython\Lib\threading.py", line 1036 in _bootstrap

Current thread's C stack trace (most recent call first):
  <cannot get C stack on this system>

Not sure why it cannot get the C stack. I used the current main branch to compile a debug build. The -VV string shows a custom branch, but it doesn't include any changes.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

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

Python 3.15.0a0 experimental free-threading build (heads/fix-thread-crash-dirty:2e1544fd2b0, Jun 5 2025, 16:53:09) [MSC v.1944 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-crashA 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