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
Copy file name to clipboardExpand all lines: guide/src/conversions/tables.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
@@ -67,7 +67,7 @@ Using Rust library types as function arguments will incur a conversion cost comp
67
67
However, once that conversion cost has been paid, the Rust standard library types offer a number of benefits:
68
68
- You can write functionality in native-speed Rust code (free of Python's runtime costs).
69
69
- You get better interoperability with the rest of the Rust ecosystem.
70
-
- You can use `Python::allow_threads` to release the Python GIL and let other Python threads make progress while your Rust code is executing.
70
+
- You can use `Python::detach` to release the Python GIL and let other Python threads make progress while your Rust code is executing.
71
71
- You also benefit from stricter type checking. For example you can specify `Vec<i32>`, which will only accept a Python `list` containing integers. The Python-native equivalent, `&PyList`, would accept a Python `list` containing Python objects of any type.
72
72
73
73
For most PyO3 usage the conversion cost is worth paying to get these benefits. As always, if you're not sure it's worth it in your case, benchmark it!
Copy file name to clipboardExpand all lines: guide/src/features.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
@@ -105,7 +105,7 @@ See [the `#[pyclass]` implementation details](class.md#implementation-details) f
105
105
106
106
### `nightly`
107
107
108
-
The `nightly` feature needs the nightly Rust compiler. This allows PyO3 to use the `auto_traits` and `negative_impls` features to fix the `Python::allow_threads` function.
108
+
The `nightly` feature needs the nightly Rust compiler. This allows PyO3 to use the `auto_traits` and `negative_impls` features to fix the `Python::detach` function.
Copy file name to clipboardExpand all lines: guide/src/migration.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,19 @@
3
3
This guide can help you upgrade code through breaking changes from one PyO3 version to the next.
4
4
For a detailed list of all changes, see the [CHANGELOG](changelog.md).
5
5
6
+
## from 0.25.* to 0.26
7
+
### Rename of `Python::with_gil` and `Python::allow_threads`
8
+
<detailsopen>
9
+
<summary><small>Click to expand</small></summary>
10
+
The names for these APIs were created when the global interpreter lock (GIL) was mandatory. With the introduction of free-threading in Python 3.13 this is no longer the case, and the naming does not has no universal meaning anymore.
11
+
For this reason we chose to rename these to more modern terminology introduced in free-threading:
12
+
-`Python::with_gil` is now called `Python::attach`, it attaches a Python thread-state to the current thread. In GIL enabled builds there can only be 1 thread attached to the interpreter, in free-threading there can be more.
13
+
-`Python::allow_threads` is now called `Python::detach`, it detaches a previously attached thread-state.
14
+
</details>
15
+
6
16
## from 0.24.* to 0.25
7
17
### `AsPyPointer` removal
8
-
<detailsopen>
18
+
<details>
9
19
<summary><small>Click to expand</small></summary>
10
20
The `AsPyPointer` trait is mostly a leftover from the now removed gil-refs API. The last remaining uses were the GC API, namely `PyVisit::call`, and identity comparison (`PyAnyMethods::is` and `Py::is`).
To enable parallel execution of this function, the [`Python::allow_threads`] method can be used to temporarily release the GIL, thus allowing other Python threads to run. We then have a function exposed to the Python runtime which calls `search_sequential` inside a closure passed to [`Python::allow_threads`] to enable true parallelism:
52
+
To enable parallel execution of this function, the [`Python::detach`] method can be used to temporarily release the GIL, thus allowing other Python threads to run. We then have a function exposed to the Python runtime which calls `search_sequential` inside a closure passed to [`Python::detach`] to enable true parallelism:
53
53
```rust,no_run
54
54
# #![allow(dead_code)]
55
55
# use pyo3::prelude::*;
@@ -68,23 +68,23 @@ To enable parallel execution of this function, the [`Python::allow_threads`] met
Now Python threads can use more than one CPU core, resolving the limitation which usually makes multi-threading in Python only good for IO-bound tasks:
77
77
```Python
78
78
from concurrent.futures import ThreadPoolExecutor
79
-
from word_count importsearch_sequential_allow_threads
0 commit comments