Skip to content

Conversation

kylebarron
Copy link
Collaborator

@kylebarron kylebarron commented Aug 29, 2025

It looks like a release of pyo3 0.26 is imminent.

  • Replace Python::with_gil with Python::attach.
  • Replace pyo3::prepare_freethreaded_python(); with Python::initialize();
  • Replace PyObject with Py<PyAny>
  • Bump MSRV to 1.74

This uses the git tag for pyo3 0.26 at the moment and will switch to the official crates.io version when 0.26 is published.

cc @davidhewitt

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, yep just waiting to fix some issues with trusted publishing and then hopefully the crates.io release will be live shortly!

Once I have it working, I'll send a PR here to configure trusted publishing too.

Just spotted a few things in this code where we can apply some TLC as we upgrade...

src/lib.rs Outdated
Comment on lines 403 to 406
static ASYNCIO: OnceCell<Py<PyAny>> = OnceCell::new();
static CONTEXTVARS: OnceCell<Py<PyAny>> = OnceCell::new();
static ENSURE_FUTURE: OnceCell<Py<PyAny>> = OnceCell::new();
static GET_RUNNING_LOOP: OnceCell<Py<PyAny>> = OnceCell::new();
Copy link
Member

Choose a reason for hiding this comment

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

I think these should probably be updated to use the new PyOnceLock (and PyOnceLock::import, potentially).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

60b735d (#54)

There are still some uses of OnceCell:

static TOKIO_RUNTIME: OnceCell<Pyo3Runtime> = OnceCell::new();

We could change them but then we'd also have to change the signatures of these public functions init_with_runtime, get_runtime, etc, to have a py: Python argument.

pub fn init_with_runtime(runtime: &'static Runtime) -> Result<(), ()> {
TOKIO_RUNTIME
.set(Pyo3Runtime::Borrowed(runtime))
.map_err(|_| ())
}

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, these ones which don't need Python can probably now be replaced with std::sync::OnceLock, which is available after we bump MSRV.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was able to remove almost all uses of once_cell, except for

static TOKIO_BUILDER: Lazy<Mutex<Builder>> = Lazy::new(|| Mutex::new(multi_thread()));

since it looks like LazyLock wasn't added to the stdlib until an MSRV of 1.80.

@kylebarron
Copy link
Collaborator Author

Can you shed some light on whether the CI failure is real?

Run cargo add tokio@=1.38.1
    Updating crates.io index
      Adding tokio =1.38.1 to optional dependencies.
             Features:
             + num_cpus
             + rt
             + rt-multi-thread
             + time
             - bytes
             - fs
             - full
             - io-std
             - io-util
             - libc
             - macros
             - mio
             - net
             - parking_lot
             - process
             - signal
             - signal-hook-registry
             - socket2
             - sync
             - test-util
             - tokio-macros
             - tracing
             - windows-sys
    Updating crates.io index
error: failed to select a version for the requirement `once_cell = "^1.21"`
candidate versions found which didn't match: 1.20.3
location searched: crates.io index
required by package `pyo3 v0.26.0`
    ... which satisfies dependency `pyo3 = "^0.26"` (locked to 0.26.0) of package `pyo3-async-runtimes v0.26.0 (/home/runner/work/pyo3-async-runtimes/pyo3-async-runtimes)`

It looks like the MSRV of pyo3 is now 1.74, while the MSRV of pyo3-async-runtimes is 1.63. Should we bump the MSRV here to match 1.74?

@davidhewitt
Copy link
Member

Ah yes, let's bump MSRV to 1.74 to match 👍

@alex
Copy link

alex commented Aug 30, 2025

Let me know if there's anything I can do to help get this merged!

@davidhewitt
Copy link
Member

Trusted publishing and 3.14 support is now done in #55

@kylebarron
Copy link
Collaborator Author

It looks like this is ready for merge! @davidhewitt

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.

Great! I think I spotted one simplification, will push a commit and merge

@davidhewitt davidhewitt merged commit 5ce66d1 into PyO3:main Sep 2, 2025
35 checks passed
@davidhewitt
Copy link
Member

Released, thanks all!

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.

3 participants