-
Notifications
You must be signed in to change notification settings - Fork 883
add RwLockExt
trait
#5435
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
add RwLockExt
trait
#5435
Conversation
f9ae19c
to
e36ab53
Compare
|
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`.
b3a5b14
to
2c7294c
Compare
2c7294c
to
055aac3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this branch today and sorry for the very slow review.
Overall this looks great, and is I think good for merge without any question about the validity of the design.
Just a few minor nits which would be great to clean up before we merge and ship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks 👍
Thanks so much for doing this! Sorry for missing this PR - if you have future PRs that are related to supporting or improving multithreaded workflows please feel free to ping my handle for speedier reviews. |
Add a new
pyo3::sync::RwLockExt
trait forstd::sync::RwLock
to detach from the Python interpreter while blocking to acquire a read or write lock on astd::sync::RwLock
. This mirrors whatpyo3::sync::MutexExt
andpyo3::sync::OnceLockExt
do forstd::sync::Mutex
andstd::sync::OnceLock
respectively. The trait is also implemented forparking_lot
's /lock_api
'sRwLock
.