Skip to content

Draft: Rename pyo3::prepare_freethreaded_python #5247

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

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

Conversation

olp-cs
Copy link

@olp-cs olp-cs commented Jul 19, 2025

Related to #5061


At EuroPython Sprints with @Cheukting

@davidhewitt davidhewitt mentioned this pull request Jul 19, 2025
@davidhewitt
Copy link
Member

Thanks for the contribution! Other than needing a newsfragment, what makes this WIP? I'd love to merge for the upcoming release.

@olp-cs
Copy link
Author

olp-cs commented Jul 20, 2025

@davidhewitt Some of the tests were failing for me locally on the main branch (even before the changes), with different error messages on Linux and macOS, so I wanted to test it additionally. I submitted it here to look at the CI/CD results. If you think that everything is fine, then you are free to merge it, of course.

@olp-cs
Copy link
Author

olp-cs commented Jul 20, 2025

@davidhewitt
Update: I’ve managed to run the tests successfully in the following macOS 11.7.10 environment:

  • platform darwin -- Python 3.12.7, pytest-8.4.1, pluggy-1.6.0
  • rustc 1.88.0 (6b00bc388 2025-06-23)

The tests are now passing in the main branch and in the initialize_python branch.


However, the tests on the main branch were failing in the default environment of GitHub Codespaces. I can collect all details and create an issue if you think it might be helpful to investigate this further (another option would be to create a .devcontainer for reproducible builds).

$ uname -a
Linux codespaces-528582 6.8.0-1027-azure #32~22.04.1-Ubuntu SMP Thu Apr  3 20:26:27 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

$ nox -s test
...
error: 3 targets failed:
    `--lib`
    `--test test_datetime`
    `--test test_pyerr_debug_unformattable`
nox > Command cargo test --no-fail-fast --no-default-features --all-targets failed with exit code 101
nox > Session test failed.

@olp-cs olp-cs changed the title Draft: Rename pyo3::prepare_freethreaded_python to pyo3::initialize_python Rename pyo3::prepare_freethreaded_python to pyo3::initialize_python Jul 20, 2025
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.

Did we rule out Python::initialize? That would sounds intuitive to me and it would be near to the other functions that interact with the runtime like Python::attach and Python::detach. Might be nice for discoveribility.

/// Python::attach(|py| py.run(pyo3::ffi::c_str!("print('Hello World')"), None, None))
/// # }
/// ```
#[cfg(not(any(PyPy, GraalPy)))]
pub fn prepare_freethreaded_python() {
pub fn initialize_python() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep the old name with a deprecation added to offer a smoother transition to users.

@olp-cs
Copy link
Author

olp-cs commented Jul 21, 2025

I agree, it makes sense. I'll need to look into the implementation.

@davidhewitt
Copy link
Member

Python::initialize is also fine with me, it probably is slightly better from a discoverability perspective. 👍

However, the tests on the main branch were failing in the default environment of GitHub Codespaces. I can collect all details and create an issue if you think it might be helpful to investigate this further (another option would be to create a .devcontainer for reproducible builds).

An issue would be helpful, yes please.

@Cheukting
Copy link
Contributor

Nicely done @olp-cs! You may find this helpful: https://rustwiki.org/en/reference/attributes/diagnostics.html#the-deprecated-attribute

An example of it in PyO3 can be found here:

#[deprecated(note = "use PyOS_AfterFork_Child instead")]

@olp-cs olp-cs changed the title Rename pyo3::prepare_freethreaded_python to pyo3::initialize_python Draft: Rename pyo3::prepare_freethreaded_python Jul 22, 2025
@olp-cs
Copy link
Author

olp-cs commented Jul 22, 2025

Thank you! I'll look into this.

An issue would be helpful, yes please.

I've created it here: #5254

@davidhewitt
Copy link
Member

@olp-cs just checking to see when you expect to have a chance to return to this? I think the agreement is that Python::initialize is slightly preferred and we need to preserve the existing API as a deprecation.

Reason why I ask - I'd love to get this into the 0.26 release, which I'd like to publish in the next week or two. I prefer to leave time for contributors to cycle back when they can and fully understand everyone has different availability and resources. In this case this rename really fits being released alongside the rename of Python::with_gil -> Python:attach which is already ready to go in 0.26.

If you don't have availability to finish this in the next couple weeks, I totally understand. I can push to this branch and finish this off if you will forgive me 🙏 .

@olp-cs
Copy link
Author

olp-cs commented Jul 27, 2025

@davidhewitt Thank you for the explanations! If you don't hear back from me by 30 July, feel free to take it over. Apologies for the delay, I was at another conference right after EuroPython, and I've just came back from Prague. I'll try to get back to this issue within the next couple of days.

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