Skip to content

Free-threaded build crashes when destructor ran in the middle of dict/list resize #160697

Closed

Description

@Eclips4

Crash report

import threading

class Evil:
    def __del__(self):
        d[object()] = 0

class C:
    pass

d = {}
t = threading.Thread(target=d.get, args=(0,))
t.start()
t.join()

for _ in range(1000):
    o = C()
    o.__dict__ = {"x": Evil()}
    o.__dict__ = {}
    for k in list(d):
        del d[k]
    for i in rang

Found this while trying to formally verify parts of CPython :)

CPython versions tested on:

3.15, 3.14, 3.16, CPython main branch

Operating systems tested on:

Linux

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

No response

Linked PRs

Activity

  1. added
    type-crash
    3.14
    3.15
    3.16
    on Oct 26, 2026
  2. added
    interpreter-core
    on Oct 26, 2026
  3. self-assigned this
    on Nov 4, 2026
  4. added a commit that references this issue on Nov 20, 2026
  5. added 4 commits that reference this issue on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.143.153.16interpreter-coretopic-free-threadingtype-crash

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions