Skip to content

Conversation

tdyas
Copy link

@tdyas tdyas commented Sep 11, 2025

Add a new pyo3::sync::RwLockExt trait for std::sync::RwLock to detach from the Python interpreter while blocking to acquire a read or write lock on a std::sync::RwLock. This mirrors what pyo3::sync::MutexExt and pyo3::sync::OnceLockExt do for std::sync::Mutex and std::sync::OnceLock respectively.

@tdyas tdyas marked this pull request as ready for review September 11, 2025 14:29
@tdyas
Copy link
Author

tdyas commented Sep 11, 2025

I plan to submit support for parking_lot::RwLock in a follow-on PR.

tdyas added a commit to pantsbuild/pants that referenced this pull request Sep 16, 2025
Upgrade the `pyo3` crate to v0.26.0. There are several migrations due to
deprecated naming [as per the migration
guide](https://pyo3.rs/main/migration.html#from-025-to-026):

- The `PyObject` type alias is removed. Switched to its expansion
`Py<PyAny>`.
- "GIL" is removed as a legacy name since the free-threaded Python in
Python 3.13+ has no GIL. Threads still "attach" to the interpreter
though so `Python::with_gil` becomes `Python::attach` and
`Python::allow_threads` becomes `Python::detach`.
- The `GILProtected` wrapper is removed in favor of just using normal
`Mutex` or `RwLock` locks. The various usages have been switched to
`Mutex` and `RwLock`. There is a very small chance of acquiring a lock
deadlocking with the GIL so PyO3 provides a helper `lock_py_attached`
method to detach, acquire the lock, and reattach. For the `RwLock` used
in `PyGeneratorResponseCall`, equivalent `read_py_attached` and
`write_py_attached` methods won't be available until my PR
PyO3/pyo3#5435 lands upstream.
-  `pyo3::prepare_freethreaded_python` becomes `Python::initialize`.
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.

1 participant