Skip to content

Bump to 0.23 #21

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

Merged
merged 11 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-async-runtimes"
description = "PyO3 bridges from Rust runtimes to Python's Asyncio library"
version = "0.22.0"
version = "0.23.0"
authors = [
"Andrew J Westlake <[email protected]>",
"David Hewitt <[email protected]>",
Expand Down Expand Up @@ -120,11 +120,11 @@ futures = "0.3"
inventory = { version = "0.3", optional = true }
once_cell = "1.14"
pin-project-lite = "0.2"
pyo3 = "0.22"
pyo3-async-runtimes-macros = { path = "pyo3-async-runtimes-macros", version = "=0.22.0", optional = true }
pyo3 = "0.23"
pyo3-async-runtimes-macros = { path = "pyo3-async-runtimes-macros", version = "=0.23.0", optional = true }

[dev-dependencies]
pyo3 = { version = "0.22", features = ["macros"] }
pyo3 = { version = "0.23", features = ["macros"] }

[dependencies.async-std]
version = "1.12"
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Here we initialize the runtime, import Python's `asyncio` library and run the gi
```toml
# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.22" }
pyo3-async-runtimes = { version = "0.22", features = ["attributes", "async-std-runtime"] }
pyo3 = { version = "0.23" }
pyo3-async-runtimes = { version = "0.23", features = ["attributes", "async-std-runtime"] }
async-std = "1.13"
```

Expand All @@ -67,9 +67,9 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::async_std::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;
// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
})?;

fut.await?;
Expand All @@ -84,8 +84,8 @@ attribute.
```toml
# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.22" }
pyo3-async-runtimes = { version = "0.22", features = ["attributes", "tokio-runtime"] }
pyo3 = { version = "0.23" }
pyo3-async-runtimes = { version = "0.23", features = ["attributes", "tokio-runtime"] }
tokio = "1.40"
```

Expand All @@ -97,9 +97,9 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::tokio::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;
// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
})?;

fut.await?;
Expand Down Expand Up @@ -130,8 +130,8 @@ For `async-std`:

```toml
[dependencies]
pyo3 = { version = "0.22", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.22", features = ["async-std-runtime"] }
pyo3 = { version = "0.23", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.23", features = ["async-std-runtime"] }
async-std = "1.13"
```

Expand All @@ -140,7 +140,7 @@ For `tokio`:
```toml
[dependencies]
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.22", features = ["tokio-runtime"] }
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime"] }
tokio = "1.40"
```

Expand Down Expand Up @@ -240,7 +240,7 @@ use pyo3::prelude::*;
async fn main() -> PyResult<()> {
let future = Python::with_gil(|py| -> PyResult<_> {
// import the module containing the py_sleep function
let example = py.import_bound("example")?;
let example = py.import("example")?;

// calling the py_sleep method like a normal function
// returns a coroutine
Expand Down Expand Up @@ -359,11 +359,11 @@ async fn main() -> PyResult<()> {
// PyO3 is initialized - Ready to go

let fut = Python::with_gil(|py| -> PyResult<_> {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::async_std::into_future(
asyncio.call_method1("sleep", (1.into_py(py),))?
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?
)
})?;

Expand Down Expand Up @@ -434,8 +434,8 @@ name = "my_async_module"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.22", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.22", features = ["tokio-runtime"] }
pyo3 = { version = "0.23", features = ["extension-module"] }
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime"] }
async-std = "1.13"
tokio = "1.40"
```
Expand Down Expand Up @@ -494,8 +494,8 @@ event loop before we can install the `uvloop` policy.
```toml
[dependencies]
async-std = "1.13"
pyo3 = "0.22"
pyo3-async-runtimes = { version = "0.22", features = ["async-std-runtime"] }
pyo3 = "0.23"
pyo3-async-runtimes = { version = "0.23", features = ["async-std-runtime"] }
```

```rust no_run
Expand All @@ -507,7 +507,7 @@ fn main() -> PyResult<()> {
pyo3::prepare_freethreaded_python();

Python::with_gil(|py| {
let uvloop = py.import_bound("uvloop")?;
let uvloop = py.import("uvloop")?;
uvloop.call_method0("install")?;

// store a reference for the assertion
Expand Down Expand Up @@ -604,7 +604,7 @@ To make things a bit easier, I decided to keep most of the old API alongside the
pyo3::prepare_freethreaded_python();

Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

let event_loop = asyncio.call_method0("new_event_loop")?;
asyncio.call_method1("set_event_loop", (&event_loop,))?;
Expand Down
4 changes: 2 additions & 2 deletions examples/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::async_std::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::async_std::into_future(
asyncio.call_method1("sleep", (1.into_py(py),))?,
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
)
})?;

Expand Down
6 changes: 4 additions & 2 deletions examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::tokio::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
pyo3_async_runtimes::tokio::into_future(
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
)
})?;

println!("sleeping for 1s");
Expand Down
6 changes: 4 additions & 2 deletions examples/tokio_current_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::tokio::main(flavor = "current_thread")]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
pyo3_async_runtimes::tokio::into_future(
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
)
})?;

println!("sleeping for 1s");
Expand Down
6 changes: 4 additions & 2 deletions examples/tokio_multi_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use pyo3::prelude::*;
#[pyo3_async_runtimes::tokio::main(flavor = "multi_thread", worker_threads = 10)]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import_bound("asyncio")?;
let asyncio = py.import("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
pyo3_async_runtimes::tokio::into_future(
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
)
})?;

println!("sleeping for 1s");
Expand Down
2 changes: 1 addition & 1 deletion pyo3-async-runtimes-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-async-runtimes-macros"
description = "Proc Macro Attributes for `pyo3-async-runtimes`"
version = "0.22.0"
version = "0.23.0"
authors = [
"Andrew J Westlake <[email protected]>",
"David Hewitt <[email protected]>",
Expand Down
17 changes: 11 additions & 6 deletions pytests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::ffi::CString;
use std::{thread, time::Duration};

use pyo3::prelude::*;
use pyo3_async_runtimes::TaskLocals;

pub(super) const TEST_MOD: &'static str = r#"
pub(super) const TEST_MOD: &str = r#"
import asyncio

async def py_sleep(duration):
Expand All @@ -15,12 +16,16 @@ async def sleep_for_1s(sleep_for):

pub(super) async fn test_into_future(event_loop: PyObject) -> PyResult<()> {
let fut = Python::with_gil(|py| {
let test_mod =
PyModule::from_code_bound(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?;
let test_mod = PyModule::from_code(
py,
&CString::new(TEST_MOD).unwrap(),
&CString::new("test_rust_coroutine/test_mod.py").unwrap(),
&CString::new("test_mod").unwrap(),
)?;

pyo3_async_runtimes::into_future_with_locals(
&TaskLocals::new(event_loop.into_bound(py)),
test_mod.call_method1("py_sleep", (1.into_py(py),))?,
test_mod.call_method1("py_sleep", (1.into_pyobject(py).unwrap(),))?,
)
})?;

Expand All @@ -36,8 +41,8 @@ pub(super) fn test_blocking_sleep() -> PyResult<()> {

pub(super) async fn test_other_awaitables(event_loop: PyObject) -> PyResult<()> {
let fut = Python::with_gil(|py| {
let functools = py.import_bound("functools")?;
let time = py.import_bound("time")?;
let functools = py.import("functools")?;
let time = py.import("time")?;

// spawn a blocking sleep in the threadpool executor - returns a task, not a coroutine
let task = event_loop.bind(py).call_method1(
Expand Down
Loading