@@ -50,8 +50,8 @@ Here we initialize the runtime, import Python's `asyncio` library and run the gi
50
50
``` toml
51
51
# Cargo.toml dependencies
52
52
[dependencies ]
53
- pyo3 = { version = " 0.25 " }
54
- pyo3-async-runtimes = { version = " 0.25 " , features = [" attributes" , " async-std-runtime" ] }
53
+ pyo3 = { version = " 0.26 " }
54
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" attributes" , " async-std-runtime" ] }
55
55
async-std = " 1.13"
56
56
```
57
57
@@ -62,10 +62,10 @@ use pyo3::prelude::*;
62
62
63
63
#[pyo3_async_runtimes:: async_std:: main]
64
64
async fn main () -> PyResult <()> {
65
- let fut = Python :: with_gil (| py | {
65
+ let fut = Python :: attach (| py | {
66
66
let asyncio = py . import (" asyncio" )? ;
67
67
// convert asyncio.sleep into a Rust Future
68
- pyo3_async_runtimes :: async_std :: into_future (asyncio . call_method1 (" sleep" , (1. into_pyobject ( py ) . unwrap () ,))? )
68
+ pyo3_async_runtimes :: async_std :: into_future (asyncio . call_method1 (" sleep" , (1 ,))? )
69
69
})? ;
70
70
71
71
fut . await ? ;
@@ -80,8 +80,8 @@ attribute.
80
80
``` toml
81
81
# Cargo.toml dependencies
82
82
[dependencies ]
83
- pyo3 = { version = " 0.25 " }
84
- pyo3-async-runtimes = { version = " 0.25 " , features = [" attributes" , " tokio-runtime" ] }
83
+ pyo3 = { version = " 0.26 " }
84
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" attributes" , " tokio-runtime" ] }
85
85
tokio = " 1.40"
86
86
```
87
87
@@ -92,10 +92,10 @@ use pyo3::prelude::*;
92
92
93
93
#[pyo3_async_runtimes:: tokio:: main]
94
94
async fn main () -> PyResult <()> {
95
- let fut = Python :: with_gil (| py | {
95
+ let fut = Python :: attach (| py | {
96
96
let asyncio = py . import (" asyncio" )? ;
97
97
// convert asyncio.sleep into a Rust Future
98
- pyo3_async_runtimes :: tokio :: into_future (asyncio . call_method1 (" sleep" , (1. into_pyobject ( py ) . unwrap () ,))? )
98
+ pyo3_async_runtimes :: tokio :: into_future (asyncio . call_method1 (" sleep" , (1 ,))? )
99
99
})? ;
100
100
101
101
fut . await ? ;
@@ -126,17 +126,17 @@ For `async-std`:
126
126
127
127
``` toml
128
128
[dependencies ]
129
- pyo3 = { version = " 0.25 " , features = [" extension-module" ] }
130
- pyo3-async-runtimes = { version = " 0.25 " , features = [" async-std-runtime" ] }
129
+ pyo3 = { version = " 0.26 " , features = [" extension-module" ] }
130
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" async-std-runtime" ] }
131
131
async-std = " 1.13"
132
132
```
133
133
134
134
For ` tokio ` :
135
135
136
136
``` toml
137
137
[dependencies ]
138
- pyo3 = { version = " 0.25 " , features = [" extension-module" ] }
139
- pyo3-async-runtimes = { version = " 0.25 " , features = [" tokio-runtime" ] }
138
+ pyo3 = { version = " 0.26 " , features = [" extension-module" ] }
139
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" tokio-runtime" ] }
140
140
tokio = " 1.40"
141
141
```
142
142
@@ -234,7 +234,7 @@ use pyo3::prelude::*;
234
234
235
235
#[pyo3_async_runtimes:: tokio:: main]
236
236
async fn main () -> PyResult <()> {
237
- let future = Python :: with_gil (| py | -> PyResult <_ > {
237
+ let future = Python :: attach (| py | -> PyResult <_ > {
238
238
// import the module containing the py_sleep function
239
239
let example = py . import (" example" )? ;
240
240
@@ -354,12 +354,12 @@ use pyo3::prelude::*;
354
354
async fn main () -> PyResult <()> {
355
355
// PyO3 is initialized - Ready to go
356
356
357
- let fut = Python :: with_gil (| py | -> PyResult <_ > {
357
+ let fut = Python :: attach (| py | -> PyResult <_ > {
358
358
let asyncio = py . import (" asyncio" )? ;
359
359
360
360
// convert asyncio.sleep into a Rust Future
361
361
pyo3_async_runtimes :: async_std :: into_future (
362
- asyncio . call_method1 (" sleep" , (1. into_pyobject ( py ) . unwrap () ,))?
362
+ asyncio . call_method1 (" sleep" , (1 ,))?
363
363
)
364
364
})? ;
365
365
@@ -430,8 +430,8 @@ name = "my_async_module"
430
430
crate-type = [" cdylib" ]
431
431
432
432
[dependencies ]
433
- pyo3 = { version = " 0.25 " , features = [" extension-module" ] }
434
- pyo3-async-runtimes = { version = " 0.25 " , features = [" tokio-runtime" ] }
433
+ pyo3 = { version = " 0.26 " , features = [" extension-module" ] }
434
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" tokio-runtime" ] }
435
435
async-std = " 1.13"
436
436
tokio = " 1.40"
437
437
```
@@ -490,8 +490,8 @@ event loop before we can install the `uvloop` policy.
490
490
``` toml
491
491
[dependencies ]
492
492
async-std = " 1.13"
493
- pyo3 = " 0.25 "
494
- pyo3-async-runtimes = { version = " 0.25 " , features = [" async-std-runtime" ] }
493
+ pyo3 = " 0.26 "
494
+ pyo3-async-runtimes = { version = " 0.26 " , features = [" async-std-runtime" ] }
495
495
```
496
496
497
497
``` rust no_run
@@ -500,18 +500,18 @@ pyo3-async-runtimes = { version = "0.25", features = ["async-std-runtime"] }
500
500
use pyo3 :: {prelude :: * , types :: PyType };
501
501
502
502
fn main () -> PyResult <()> {
503
- pyo3 :: prepare_freethreaded_python ();
503
+ Python :: initialize ();
504
504
505
- Python :: with_gil (| py | {
505
+ Python :: attach (| py | {
506
506
let uvloop = py . import (" uvloop" )? ;
507
507
uvloop . call_method0 (" install" )? ;
508
508
509
509
// store a reference for the assertion
510
- let uvloop = PyObject :: from ( uvloop );
510
+ let uvloop : Py < PyAny > = uvloop . into ( );
511
511
512
512
pyo3_async_runtimes :: async_std :: run (py , async move {
513
513
// verify that we are on a uvloop.Loop
514
- Python :: with_gil (| py | -> PyResult <()> {
514
+ Python :: attach (| py | -> PyResult <()> {
515
515
assert! (uvloop
516
516
. bind (py )
517
517
. getattr (" Loop" )?
0 commit comments