Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,46 @@ For this reason we chose to rename these to more modern terminology introduced i
- `pyo3::prepare_freethreaded_python` is now called `Python::initialize`.
</details>

### Deprecation of `GILProtected`
<details open>
<summary><small>Click to expand</small></summary>

As another cleanup related to concurrency primitives designed for a Python constrained by the GIL, the `GILProtected` type is now deprecated. Prefer to use concurrency primitives which are compatible with free-threaded Python, such as [`std::sync::Mutex`](https://doc.rust-lang.org/std/sync/struct.Mutex.html) (in combination with PyO3's [`OnceExt`]({{#PYO3_DOCS_URL}}/pyo3/sync/trait.OnceExt.html) trait).

Before:

```rust
# #![allow(deprecated)]
# use pyo3::prelude::*;
use pyo3::sync::GILProtected;
use std::cell::RefCell;
# fn main() {
# Python::attach(|py| {
static NUMBERS: GILProtected<RefCell<Vec<i32>>> = GILProtected::new(RefCell::new(Vec::new()));
Python::attach(|py| {
NUMBERS.get(py).borrow_mut().push(42);
});
# })
# }
```

After:

```rust
# use pyo3::prelude::*;
use pyo3::sync::MutexExt;
use std::sync::Mutex;
# fn main() {
# Python::attach(|py| {
static NUMBERS: Mutex<Vec<i32>> = Mutex::new(Vec::new());
Python::attach(|py| {
NUMBERS.lock_py_attached(py).expect("no poisoning").push(42);
});
# })
# }
```
</summary>

## from 0.24.* to 0.25
### `AsPyPointer` removal
<details>
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5285.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `GILProtected`.
4 changes: 4 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ use crate::PyVisit;
/// NUMBERS.get(py).borrow_mut().push(42);
/// });
/// ```
#[deprecated(
since = "0.26.0",
note = "Prefer an interior mutability primitive compatible with free-threaded Python, such as `Mutex` in combination with the `MutexExt` trait"
)]
#[cfg(not(Py_GIL_DISABLED))]
pub struct GILProtected<T> {
value: T,
Expand Down
Loading