-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python::with_pool as a safe alternative to GILPool usage.
- Loading branch information
1 parent
3ec966d
commit 2973477
Showing
8 changed files
with
126 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add `Python::with_pool` as a safe alternative to `Python::new_pool` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Deprecate `Python::new_pool` as the safe alternative `Python::with_pool` was added. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use pyo3::prelude::*; | ||
|
||
fn reuse_old_token_in_with_pool(old_py: Python<'_>) { | ||
old_py.with_pool(|new_py| { drop(old_py); }); | ||
} | ||
|
||
fn main() { | ||
Python::with_gil(|py| { | ||
reuse_old_token_in_with_pool(py); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safely | ||
--> tests/ui/with_pool.rs:4:22 | ||
| | ||
4 | old_py.with_pool(|new_py| { drop(old_py); }); | ||
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut pyo3::Python<'static>` cannot be shared between threads safely | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>` | ||
= note: required because it appears within the type `PhantomData<*mut Python<'static>>` | ||
= note: required because it appears within the type `NotSend` | ||
= note: required because it appears within the type `(&EnsureGIL, NotSend)` | ||
= note: required because it appears within the type `PhantomData<(&EnsureGIL, NotSend)>` | ||
= note: required because it appears within the type `Python<'_>` | ||
= note: required for `&pyo3::Python<'_>` to implement `Send` | ||
note: required because it's used within this closure | ||
--> tests/ui/with_pool.rs:4:22 | ||
| | ||
4 | old_py.with_pool(|new_py| { drop(old_py); }); | ||
| ^^^^^^^^ | ||
= note: required for `[closure@$DIR/tests/ui/with_pool.rs:4:22: 4:30]` to implement `Ungil` | ||
note: required by a bound in `pyo3::Python::<'_>::with_pool` | ||
--> src/marker.rs | ||
| | ||
| F: for<'py> FnOnce(Python<'py>) -> R + Ungil, | ||
| ^^^^^ required by this bound in `Python::<'_>::with_pool` |