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 — gh-104341: Fix threading Module Shutdown by ericsnowcurrently · Pull Request #104560 · python/cpython

Conversation

@ericsnowcurrently

@ericsnowcurrently ericsnowcurrently commented May 16, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This should fix the frequent crashes in test_threading and test__xxsubinterpreters.

There is some duplication with the threading module which could be removed after this lands. We can also eliminate PyThreadState.on_delete and PyInterpreterState.threads.count, both of which are cases where the state of the threading module leaked out into the runtime.

(Also see gh-63008 and gh-18296.)

  • Issue: test__xxsubinterpreters is Occasionally Crashing #104341

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ericsnowcurrently added 6 commits May 16, 2023 11:02
@ericsnowcurrently
Add module-owned threads to module state.
e5804c1
@ericsnowcurrently
Re-initialize the module threads lock upon fork.
62df3e6
@ericsnowcurrently
Add module_thread.daemonic.
1bf707f
@ericsnowcurrently
Add module_thread.lifetime_mutex.
da78235
@ericsnowcurrently
Add _thread._wait_for_threads_fini().
ad9bbce
@ericsnowcurrently
Wait for all the threads to finalize.
54dc3b5
@ericsnowcurrently ericsnowcurrently added the skip news label May 16, 2023
@bedevere-bot bedevere-bot added the awaiting core review label May 16, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 16, 2023
test__xxsubinterpreters is Occasionally Crashing #104341
Closed
ericsnowcurrently
ericsnowcurrently commented May 16, 2023
View reviewed changes
Comment thread Modules/_threadmodule.c Outdated
Comment on lines +86 to +92
PyThread_acquire_lock(threads->mutex, WAIT_LOCK);
while (threads->head != NULL) {
PyThread_release_lock(threads->mutex);
// XXX Sleep?
PyThread_acquire_lock(threads->mutex, WAIT_LOCK);
}
PyThread_release_lock(threads->mutex);

@ericsnowcurrently ericsnowcurrently May 16, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this doesn't feel right. I'm going to look at what my options are. A condvar would work, but that doesn't seem to be something we do in CPython outside the GIL.

(I'm also open to ideas.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ericsnowcurrently ericsnowcurrently May 16, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've come up with a slightly better approach.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ericsnowcurrently
ericsnowcurrently requested review from markshannon, pitrou and tim-one May 16, 2023 19:34
ericsnowcurrently added 3 commits May 16, 2023 13:39
@ericsnowcurrently
Fix Windows.
b15fa9d
@ericsnowcurrently
Fix Windows.
c7a832b
@ericsnowcurrently
Fix Windows.
51d960e
@ericsnowcurrently ericsnowcurrently added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 16, 2023
@bedevere-bot

bedevere-bot commented May 16, 2023

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @ericsnowcurrently for commit 51d960e 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 16, 2023
@ericsnowcurrently
Wait for all threads that aren't killed daemon threads to finalize.
bddfc46
adr26
adr26 reviewed May 16, 2023
View reviewed changes
Comment thread Modules/_threadmodule.c Outdated
static struct PyModuleDef thread_module;


/* threads owned by the modulo */

@adr26 adr26 May 16, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: module?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ericsnowcurrently reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@ericsnowcurrently ericsnowcurrently May 16, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ericsnowcurrently added 2 commits May 16, 2023 16:31
@ericsnowcurrently
Fix a typo.
188d141
@ericsnowcurrently
Silence some warnings.
bd3accd
@ericsnowcurrently

ericsnowcurrently commented May 17, 2023

Copy link
Copy Markdown
Member Author

FTR, I ran the buildbots on commit 51d960e: https://buildbot.python.org/all/#/changes/22637.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericsnowcurrently

ericsnowcurrently commented May 17, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Based on CI and the buildbots, I'm thinking there may be something wrong with this PR on macOS. I'll take a look.


Run failed when multiple fork-related tests timed out:

  • https://github.com/python/cpython/actions/runs/4996253064/jobs/8949214929 (commit 51d960e)
  • https://github.com/python/cpython/actions/runs/4997616864/jobs/8952165246 (commit bd3accd)
  • https://buildbot.python.org/all/#/builders/721/builds/1163/steps/5/logs/stdio ("ARM64 macOS PR")

On the "x86-64 macOS PR" builder, the run was cancelled 3 times:

  • https://buildbot.python.org/all/#/builders/311/builds/1311
  • https://buildbot.python.org/all/#/builders/311/builds/1310
  • https://buildbot.python.org/all/#/builders/311/builds/1309
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericsnowcurrently

ericsnowcurrently commented May 17, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

CI run 1

(https://github.com/python/cpython/actions/runs/4996253064/jobs/8949214929)

12 test modules failed before the CI job was canceled.

(details)

test module timed out after 20 minutes (1200s):

  • test_multiprocessing_main_handling (test_directory_compiled)
  • test_httpservers (test_accept)
  • test_fork1 (test_wait in fork_wait.py)
  • test_thread (test_forkinthread)
  • test_socketserver (test_forking_handled)
  • test_asyncio (test_fork_asyncio_run)
  • test_os (test_fork_warns_when_non_python_thread_exists)

individual tests timed out:

  • test.fork_wait.ForkWait.test_wait, via test_wait4 (300s)
  • test.test_wait4.Wait4Test.test_wait (30s)
  • test.test_tracemalloc.TestTracemallocEnabled.test_fork (300s)
  • test.test_pty.PtyTest.test_fork
  • test.test_pty.PtyTest.test_spawn_doesnt_hang
  • test.test_uuid.TestUUIDWithExtModule.testIssue8621 (300s)
  • test.test_uuid.TestUUIDWithoutExtModule.testIssue8621 (300s)
  • test.test_support.TestSupport.test_reap_children (30s)
  • test.test_support.TestSupport.test_temp_dir__forked_child (300s)

still running:

  • test_mailbox
  • test_wait3
  • test_tempfile
  • test_random

CI run 2

(https://github.com/python/cpython/actions/runs/4997616864/jobs/8952165246)

12 test modules failed before the CI job was canceled.

(details)

test module timed out after 20 minutes (1200s):

  • test_thread (test_forkinthread)
  • test_subprocess (test_close_fds_after_preexec)
  • test_concurrent_futures (tearDown)
  • test_builtin (test_input_no_stdout_fileno)
  • test_socketserver (test_forking_handled)
  • test_httpservers (test_accept)
  • test.test_asyncio.test_unix_events (test_fork_asyncio_run)

individual tests timed out:

  • test.fork_wait.ForkWait.test_wait, via test_wait3 (300s)
  • test.test_wait3.Wait3Test.test_wait (30s)
  • test.test_uuid.TestUUIDWithExtModule.testIssue8621 (300s)
  • test.test_uuid.TestUUIDWithoutExtModule.testIssue8621 (300s)
  • test.fork_wait.ForkWait.test_wait, via test_wait4 (300s)
  • test.test_wait4.Wait4Test.test_wait (30s)
  • test.test_pty.PtyTest.test_fork
  • test.test_logging.HandlerTest.test_post_fork_child_no_deadlock (300s)

still running:

  • test_multiprocessing_spawn
  • test_multiprocessing_main_handling
  • test_os
  • test_tempfile

Buildbot (ARM64 macOS PR)

(https://buildbot.python.org/all/#/builders/721/builds/1163/steps/5/logs/stdio)

25 test modules failed

(details)

test module timed out after 15 minutes (900s):

  • test_httpservers (test_accept)
  • test_threading (test_clear_threads_states_after_fork)
  • test_fork1 (test_wait in fork_wait.py)
  • test_concurrent_futures (test_duplicate_futures)
  • test_multiprocessing_spawn (test_context)
  • test_tempfile (test_noinherit)
  • test_socketserver (test_forking_handled)
  • test_os (test_fork_warns_when_non_python_thread_exists)
  • test_mailbox (test_lock_conflict)
  • test_subprocess (test_close_fds_after_preexec)
  • test_thread (test_forkinthread)
  • test.test_asyncio.test_unix_events (test_fork_asyncio_run)
  • test_multiprocessing_main_handling (test_directory)
  • test_builtin (test_input_no_stdout_fileno)
  • test_cmd_line (test_no_std_streams)
  • test_random (test_after_fork)
  • test_multiprocessing_forkserver (test_closefd)

individual tests timed out:

  • test.test_tracemalloc.TestTracemallocEnabled.test_fork (300s)
  • test.fork_wait.ForkWait.test_wait, via test_wait4 (300s)
  • test.test_wait4.Wait4Test.test_wait (30s)
  • test.test_support.TestSupport.test_reap_children (30s)
  • test.test_support.TestSupport.test_temp_dir__forked_child (300s)
  • test.fork_wait.ForkWait.test_wait, via test_wait3 (300s)
  • test.test_wait3.Wait3Test.test_wait (30s)
  • test.test_platform.PlatformTest.test_mac_ver_with_fork (300s)
  • test.test_pty.PtyTest.test_fork
  • test.test_pty.PtyTest.test_spawn_doesnt_hang
  • test.test_logging.HandlerTest.test_post_fork_child_no_deadlock (300s)
  • test.test_uuid.TestUUIDWithExtModule.testIssue8621 (300s)
  • test.test_uuid.TestUUIDWithoutExtModule.testIssue8621 (300s)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented May 17, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I reran the job and got the same result (the tests are not done yet but started to time out already).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericsnowcurrently
ericsnowcurrently marked this pull request as draft May 18, 2023 16:57
@bedevere-bot bedevere-bot removed the awaiting core review label May 18, 2023
@github-actions

github-actions Bot commented Apr 13, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 13, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This PR is attached to gh-104341, which is already completed: the fix for that issue landed through other changes, and this PR's approach was not taken or has since become obsolete. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pitrou pitrou Awaiting requested review from pitrou
@tim-one tim-one Awaiting requested review from tim-one
@markshannon markshannon Awaiting requested review from markshannon
1 more reviewer
@adr26 adr26 adr26 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@ericsnowcurrently @bedevere-bot @arhadthedev @ambv @adr26
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.