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 — Interpreter shutdown can deadlock when a daemon thread holds the warnings lock · Issue #159485 · python/cpython

Interpreter shutdown can deadlock when a daemon thread holds the warnings lock #159485

New issue
Copy link
New issue
Copy link
Open
Open
Interpreter shutdown can deadlock when a daemon thread holds the warnings lock#159485
Copy link
Assignees
ngoldbaum
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ngoldbaum
ngoldbaum
opened on Oct 15, 2026
Issue body actions

Originally reported by @krassowski in #158973.

A daemon thread can be stopped while holding the warnings lock. During interpreter finalization, garbage collection triggers a ResourceWarning, deadlocking the finalizing thread:

import threading
import time
import warnings

ready = threading.Event()
warnings.simplefilter("always", ResourceWarning)

class WarnAtShutdown:
    def __init__(self):
        self.self_ref = self  # Defer __del__ until shutdown GC.

    def __del__(self):
        warnings.warn("late", ResourceWarning)

def showwarning(message, *args, **kwargs):
    if str(message) == "hold":
        ready.set()
        time.sleep(0.1)

warnings.showwarning = showwarning
threading.Thread(
    target=lambda: warnings.warn("hold", ResourceWarning),
    daemon=True,
).start()
assert ready.wait(4)
WarnAtShutdown()

Expected: the process exits normally. Actual: it hangs during interpreter shutdown.

  • CPython versions tested on: 3.14.8, 3.15.0.
  • Operating systems tested on: macOS.

Linked PRs

  • gh-159485: Fix warnings lock deadlock during interpreter shutdown #159488

Activity

  1. ngoldbaum
    self-assigned this
    on Oct 15, 2026
  2. ngoldbaum
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Oct 15, 2026
  3. ngoldbaum
    added a commit that references this issue on Oct 15, 2026

    pythongh-159485: Fix warnings lock deadlock during interpreter shutdown

    37baa8f
  4. ngoldbaum commented on Oct 16, 2026

    @ngoldbaum
    ngoldbaum
    on Oct 16, 2026
    ContributorAuthor
    More actions

    I updated the reproducer script in the issue to avoid an unbounded wait (it now just does time.sleep(0.1) like test_threading does). This is more realistic and is fixed by @ZeroIntensity's InterpreterGuard approach. There's no need to guard against waiting forever in a callback like my original reproducer was arguing for. There's still a deadlock even without that and the InterpreterGuard fixes it.

  5. ngoldbaum
    added 2 commits that reference this issue on Oct 16, 2026

    pythongh-159485: Hold an interpreter guard while using the warnings lock

    fdec193

    pythongh-159485: Use the public interpreter guard API for the warning…

    538a842
  6. kevinprimeraquecreo-stack
    added this to Project_VKand Project_VKon Oct 18, 2026
  7. github-project-automation
    moved this to In progress in Project_VKon Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ngoldbaum
    ngoldbaum

Labels

3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-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.