Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hang instead of pthread_exit during interpreter shutdown #4874

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented Jan 26, 2025

This mimics the Python 3.14 behavior and avoids crashes in Rust 1.84.

See python/cpython#87135 and rust-lang/rust#135929 and the related pyo3-log issue vorner/pyo3-log#30

By submitting these contributions you agree for them to be dual-licensed under PyO3's MIT OR Apache-2.0 license.

Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Performance Report

Merging #4874 will not alter performance

Comparing arielb1:safe-exit (c9dd539) with main (2c732a7)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 85 untouched benchmarks

@arielb1 arielb1 force-pushed the safe-exit branch 4 times, most recently from 80f138a to 704ef0b Compare January 27, 2025 23:24
@arielb1
Copy link
Contributor Author

arielb1 commented Jan 27, 2025

Yay it passes tests.

@@ -3,7 +3,7 @@

from pyo3_pytests import othermod

INTEGER32_ST = st.integers(min_value=(-(2**31)), max_value=(2**31 - 1))
INTEGER32_ST = st.integers(min_value=(-(2**30)), max_value=(2**30 - 1))
Copy link
Contributor Author

@arielb1 arielb1 Jan 28, 2025

Choose a reason for hiding this comment

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

this change here is to avoid the test failing due to a high rate of assume failure (filter_too_much).

@arielb1
Copy link
Contributor Author

arielb1 commented Jan 29, 2025

split the test_double fix to #4879

@arielb1
Copy link
Contributor Author

arielb1 commented Feb 17, 2025

any update?

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

This looks fine to me, but I would like at least one other maintainers opinion (maybe @davidhewitt?) before proceeding here.

@davidhewitt
Copy link
Member

Please forgive the delay, I will seek to review this on Friday, and ping me repeatedly from then if I do not achieve that!

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, I think let's move forward with this. The cfg guards hack around the various edge cases and, as I read it, the interaction with pthread_exit and rust destructors was (and still is) UB, so this just creates a practical solution for now. Ultimately 3.14 will make this problem go away.

@davidhewitt davidhewitt added this pull request to the merge queue Feb 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 19, 2025
@mgorny mgorny mentioned this pull request Feb 19, 2025
7 tasks
@arielb1
Copy link
Contributor Author

arielb1 commented Feb 19, 2025

So the scary failure here is the CodSpeed regression?

@davidhewitt
Copy link
Member

The failed stage is test-debug in https://github.com/PyO3/pyo3/actions/runs/13411900757/job/37463833819#step:9:8211, looks like the test might be triggering a debug build assertion?

I assume it's probably fine and we should just skip the new test on debug builds? After all, we're trying to test a bad edge case.

@davidhewitt
Copy link
Member

Agreed RE flaky benchmark, I will set that one to be ignored.

@arielb1
Copy link
Contributor Author

arielb1 commented Feb 19, 2025

python: Python/pystate.c:345: void unbind_gilstate_tstate(PyThreadState *): Assertion `tstate == tstate_tss_get(&(tstate->interp->runtime)->autoTSSkey)' failed.

This looks bad. Not sure it's our fault tho. Trying to investigate - if it's PyO3's fault, we should fix it. I want to know whether it's a CPython or a PyO3 problem.

@arielb1
Copy link
Contributor Author

arielb1 commented Feb 19, 2025

I didn't manage to debug it easily, will try more after Rust Nation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants