KEMBAR78
gh-136003: Execute pre-finalization callbacks in a loop by ZeroIntensity · Pull Request #136004 · python/cpython · GitHub
Skip to content

Conversation

@ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Jun 26, 2025

/* Each of these functions can start one another, e.g. a pending call
* could start a thread or vice versa. To ensure that we properly clean
* call everything, we run these in a loop until none of them run anything. */
for (;;) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add an arbitrary limit to detect infinite loop? For example, log an error after 16 attemps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it would prevent deadlocks in rare cases, but it would cause crashes in other equally rare cases. Maybe it would be better to emit a fatal error when there are too many iterations?

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

Overall, good work. 😄

I'm pretty sure there's a race we need to deal with which will require a variety of changes to this PR.

@bedevere-app
Copy link

bedevere-app bot commented Jul 3, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@ZeroIntensity
Copy link
Member Author

ZeroIntensity commented Sep 17, 2025

The failing CI jobs are due to Ubuntu being weird, and should disappear when I rerun the job. But I'll take that as a sign that I should run the buildbots before merging this.

@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 17, 2025
@bedevere-bot

This comment was marked as outdated.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 17, 2025
@ZeroIntensity
Copy link
Member Author

Nevermind, I broke FT when I fixed the merge conflicts. Ugh.

@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 17, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit e202848 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136004%2Fmerge

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 17, 2025
@ZeroIntensity
Copy link
Member Author

@ericsnowcurrently I'll hold off on merging until we talk tomorrow. We might want to extend the check to subinterpreters, and then disallow creating new interpreters during finalization.

@ZeroIntensity ZeroIntensity merged commit 2191497 into python:main Sep 18, 2025
45 checks passed
@ZeroIntensity ZeroIntensity deleted the fix-circular-finalization branch September 18, 2025 12:29
@github-project-automation github-project-automation bot moved this from Todo to Done in Sprint 2024 Sep 18, 2025
ZeroIntensity added a commit that referenced this pull request Sep 18, 2025
…ization (GH-139129)

During finalization, we need to mark all non-daemon threads as daemon to quickly shut down threads when sending CTRL^C to the process. This was a minor regression from GH-136004.
encukou added a commit that referenced this pull request Sep 22, 2025
This fixes file descriptor leaks introduced in GH-136004
ZeroIntensity added a commit that referenced this pull request Oct 15, 2025
…ng finalization (GH-140103)

This fixes a regression introduced by GH-136004, in which finalization would hang while executing atexit handlers if the system was out of memory.

---------

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants