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 — `ThreadPoolExecutorTest.test_no_stale_references` may hang with GIL disabled · Issue #117688 · python/cpython

ThreadPoolExecutorTest.test_no_stale_references may hang with GIL disabled #117688

New issue
Copy link
New issue
Copy link
Closed
Closed
ThreadPoolExecutorTest.test_no_stale_references may hang with GIL disabled#117688
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-free-threading

Description

@colesbury
colesbury
opened on Apr 9, 2024
Issue body actions

In #114824, I modified test_no_stale_references so that it passes in the --disable-gil build. Unfortunately, that change was not sufficient and the test may still hang once the GIL is actually disabled.

Relevant code:

cpython/Lib/test/test_concurrent_futures/executor.py

Lines 84 to 87 in a25c02e

my_object = MyObject()
my_object_collected = threading.Event()
my_object_callback = weakref.ref(
my_object, lambda obj: my_object_collected.set())

cpython/Lib/test/test_concurrent_futures/executor.py

Line 103 in a25c02e

collected = my_object_collected.wait(timeout=support.SHORT_TIMEOUT)

The problem is due to the combination of two issues:

  • Due to biased reference counting, the destructor for my_object is usually called on the main thread asynchronously (by the eval breaker logic)
  • The destructor may be called somewhere in the implementation of my_object_collected.wait(). The my_object_collected.wait() implementation holds some of the same locks that my_object_collected.set() also needs. This can lead to deadlock if the timing is unlucky: the my_object_collected.set() call from the weakref callback tries to acquire locks already held by the current thread and deadlocks.

Linked PRs

  • gh-117688: Fix deadlock in test_no_stale_references with GIL disabled #117720

Activity

  1. colesbury
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    topic-free-threading
    on Apr 9, 2024
  2. colesbury
    added 4 commits that reference this issue on Apr 9, 2024

    pythongh-117688: Fix deadlock in test_no_stale_references with GIL di…

    1ce167b

    Merge branch 'pythongh-117688-test_no_stale_references' into nogil-in…

    b856049

    Merge branch 'pythongh-117688-test_no_stale_references' into nogil-in…

    e27a2d6

    gh-117688: Fix deadlock in test_no_stale_references with GIL disabled (…

    520cf21
  3. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-117688: Fix deadlock in test_no_stale_references with GIL di…

    d203263
  4. colesbury
    closed this as completedon Apr 26, 2024
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

    testsTests in the Lib/test dirTests in the Lib/test dirtopic-free-threading

    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.