You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement OnceExt & MutexExt for parking_lot & lock_api (#5044)
* Implement `OnceExt` & `MutexExt` for `parking_lot` & `lock_api`
* Implement `MutexExt` for `Arc<lock_api::Mutex>`
* Move `MutexExt` lock result into type parameter
* Remove lifetime from associated type of `OnceExt`
* Add docs
* add changelog
* Add new features to `full`
* mention `parking_lot` in guide
* Add tests
* Update docs to mention all cargo features
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
* Also test `parking_lot::Mutex::lock_py_attached` on `lock_api` feature
* Update newsfragments/5044.added.md
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
* Add additional case to `once_ext` test
* enable `arc_lock` feature on `parking_lot` during testing
---------
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Copy file name to clipboardExpand all lines: guide/src/class/thread-safety.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ impl MyClass {
101
101
}
102
102
```
103
103
104
-
If you need to lock around state stored in the Python interpreter or otherwise call into the Python C API while a lock is held, you might find the `MutexExt` trait useful. It provides a `lock_py_attached` method for `std::sync::Mutex` that avoids deadlocks with the GIL or other global synchronization events in the interpreter.
104
+
If you need to lock around state stored in the Python interpreter or otherwise call into the Python C API while a lock is held, you might find the `MutexExt` trait useful. It provides a `lock_py_attached` method for `std::sync::Mutex` that avoids deadlocks with the GIL or other global synchronization events in the interpreter. Additionally, support for the `parking_lot` and `lock_api` synchronization libraries is gated behind the `parking_lot` and `lock_api` features. You can also enable the `arc_lock` feature if you need the `arc_lock` features of either library.
Copy file name to clipboardExpand all lines: guide/src/features.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,10 @@ These features enable conversions between Python types and types from other Rust
121
121
122
122
Adds a dependency on [anyhow](https://docs.rs/anyhow). Enables a conversion from [anyhow](https://docs.rs/anyhow)’s [`Error`](https://docs.rs/anyhow/latest/anyhow/struct.Error.html) type to [`PyErr`]({{#PYO3_DOCS_URL}}/pyo3/struct.PyErr.html), for easy error handling.
123
123
124
+
### `arc_lock`
125
+
126
+
Enables Pyo3's `MutexExt` trait for all Mutexes that extend on [`lock_api::Mutex`](https://docs.rs/lock_api/latest/lock_api/struct.Mutex.html) and are wrapped in an [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) type. Like [`Arc<parking_lot::Mutex>`](https://docs.rs/parking_lot/latest/parking_lot/type.Mutex.html#method.lock_arc)
127
+
124
128
### `bigdecimal`
125
129
Adds a dependency on [bigdecimal](https://docs.rs/bigdecimal) and enables conversions into its [`BigDecimal`](https://docs.rs/bigdecimal/latest/bigdecimal/struct.BigDecimal.html) type.
126
130
@@ -168,6 +172,10 @@ Adds a dependency on [jiff@0.2](https://docs.rs/jiff/0.2) and requires MSRV 1.70
Adds a dependency on [lock_api](https://docs.rs/lock_api) and enables Pyo3's `MutexExt` trait for all mutexes that extend on [`lock_api::Mutex`](https://docs.rs/lock_api/latest/lock_api/struct.Mutex.html) (like `parking_lot` or `spin`).
178
+
171
179
### `num-bigint`
172
180
173
181
Adds a dependency on [num-bigint](https://docs.rs/num-bigint) and enables conversions into its [`BigInt`](https://docs.rs/num-bigint/latest/num_bigint/struct.BigInt.html) and [`BigUint`](https://docs.rs/num-bigint/latest/num_bigint/struct.BigUint.html) types.
@@ -186,6 +194,10 @@ Adds a dependency on [ordered-float](https://docs.rs/ordered-float) and enables
Adds a dependency on [parking_lot](https://docs.rs/parking_lot) and enables Pyo3's `OnceExt` & `MutexExt` traits for [`parking_lot::Once`](https://docs.rs/parking_lot/latest/parking_lot/struct.Once.html) and [`parking_lot::Mutex`](https://docs.rs/parking_lot/latest/parking_lot/type.Mutex.html) types.
200
+
189
201
### `rust_decimal`
190
202
191
203
Adds a dependency on [rust_decimal](https://docs.rs/rust_decimal) and enables conversions into its [`Decimal`](https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html) type.
Implement `OnceExt` & `MutexExt` for `parking_lot` & `lock_api`. Use the new extension traits by enabling the `arc_lock`, `lock_api`, or `parking_lot` cargo features.
0 commit comments