File tree Expand file tree Collapse file tree 9 files changed +135
-3
lines changed Expand file tree Collapse file tree 9 files changed +135
-3
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,24 @@ path = "pytests/test_tokio_multi_thread_run_forever.rs"
83
83
harness = false
84
84
required-features = [" tokio-runtime" , " testing" ]
85
85
86
+ [[test ]]
87
+ name = " test_async_std_uvloop"
88
+ path = " pytests/test_async_std_uvloop.rs"
89
+ harness = false
90
+ required-features = [" async-std-runtime" , " testing" ]
91
+
92
+ [[test ]]
93
+ name = " test_tokio_current_thread_uvloop"
94
+ path = " pytests/test_tokio_current_thread_uvloop.rs"
95
+ harness = false
96
+ required-features = [" tokio-runtime" , " testing" ]
97
+
98
+ [[test ]]
99
+ name = " test_tokio_multi_thread_uvloop"
100
+ path = " pytests/test_tokio_multi_thread_uvloop.rs"
101
+ harness = false
102
+ required-features = [" tokio-runtime" , " testing" ]
103
+
86
104
[dependencies ]
87
105
clap = { version = " 2.33" , optional = true }
88
106
futures = " 0.3"
Original file line number Diff line number Diff line change @@ -482,7 +482,7 @@ pyo3 = "0.14"
482
482
pyo3-asyncio = { version = " 0.14" , features = [" async-std-runtime" ] }
483
483
```
484
484
485
- ``` rust
485
+ ``` rust no_run
486
486
// ! main.rs
487
487
488
488
use pyo3 :: {prelude :: * , types :: PyType };
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ fn main() {
40
40
41
41
event_loop. call_method0 ( "run_forever" ) ?;
42
42
43
- println ! ( "test test_run_forever ... ok" ) ;
43
+ println ! ( "test test_async_std_run_forever ... ok" ) ;
44
44
Ok ( ( ) )
45
45
} )
46
46
. map_err ( |e| Python :: with_gil ( |py| dump_err ( py, e) ) )
Original file line number Diff line number Diff line change
1
+ use pyo3:: { prelude:: * , types:: PyType } ;
2
+
3
+ #[ cfg( not( target_os = "windows" ) ) ]
4
+ fn main ( ) -> PyResult < ( ) > {
5
+ pyo3:: prepare_freethreaded_python ( ) ;
6
+
7
+ Python :: with_gil ( |py| {
8
+ let uvloop = py. import ( "uvloop" ) ?;
9
+ uvloop. call_method0 ( "install" ) ?;
10
+
11
+ // store a reference for the assertion
12
+ let uvloop = PyObject :: from ( uvloop) ;
13
+
14
+ pyo3_asyncio:: async_std:: run ( py, async move {
15
+ // verify that we are on a uvloop.Loop
16
+ Python :: with_gil ( |py| -> PyResult < ( ) > {
17
+ assert ! ( uvloop
18
+ . as_ref( py)
19
+ . getattr( "Loop" ) ?
20
+ . downcast:: <PyType >( )
21
+ . unwrap( )
22
+ . is_instance( pyo3_asyncio:: async_std:: get_current_loop( py) ?) ?) ;
23
+ Ok ( ( ) )
24
+ } ) ?;
25
+
26
+ async_std:: task:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
27
+
28
+ println ! ( "test test_async_std_uvloop ... ok" ) ;
29
+ Ok ( ( ) )
30
+ } )
31
+ } )
32
+ }
33
+
34
+ #[ cfg( target_os = "windows" ) ]
35
+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ fn main() {
12
12
} ) ;
13
13
14
14
tokio_run_forever:: test_main ( ) ;
15
+ println ! ( "test test_tokio_current_thread_run_forever ... ok" ) ;
15
16
}
Original file line number Diff line number Diff line change
1
+ use pyo3:: { prelude:: * , types:: PyType } ;
2
+
3
+ #[ cfg( not( target_os = "windows" ) ) ]
4
+ fn main ( ) -> PyResult < ( ) > {
5
+ pyo3:: prepare_freethreaded_python ( ) ;
6
+
7
+ let mut builder = tokio:: runtime:: Builder :: new_current_thread ( ) ;
8
+ builder. enable_all ( ) ;
9
+
10
+ pyo3_asyncio:: tokio:: init ( builder) ;
11
+ std:: thread:: spawn ( move || {
12
+ pyo3_asyncio:: tokio:: get_runtime ( ) . block_on ( futures:: future:: pending :: < ( ) > ( ) ) ;
13
+ } ) ;
14
+
15
+ Python :: with_gil ( |py| {
16
+ let uvloop = py. import ( "uvloop" ) ?;
17
+ uvloop. call_method0 ( "install" ) ?;
18
+
19
+ // store a reference for the assertion
20
+ let uvloop = PyObject :: from ( uvloop) ;
21
+
22
+ pyo3_asyncio:: tokio:: run ( py, async move {
23
+ // verify that we are on a uvloop.Loop
24
+ Python :: with_gil ( |py| -> PyResult < ( ) > {
25
+ assert ! ( uvloop
26
+ . as_ref( py)
27
+ . getattr( "Loop" ) ?
28
+ . downcast:: <PyType >( )
29
+ . unwrap( )
30
+ . is_instance( pyo3_asyncio:: tokio:: get_current_loop( py) ?) ?) ;
31
+ Ok ( ( ) )
32
+ } ) ?;
33
+
34
+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
35
+
36
+ println ! ( "test test_tokio_current_thread_uvloop ... ok" ) ;
37
+ Ok ( ( ) )
38
+ } )
39
+ } )
40
+ }
41
+
42
+ #[ cfg( target_os = "windows" ) ]
43
+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ mod tokio_run_forever;
3
3
fn main ( ) {
4
4
pyo3:: prepare_freethreaded_python ( ) ;
5
5
tokio_run_forever:: test_main ( ) ;
6
+ println ! ( "test test_tokio_multi_thread_run_forever ... ok" ) ;
6
7
}
Original file line number Diff line number Diff line change
1
+ use pyo3:: { prelude:: * , types:: PyType } ;
2
+
3
+ #[ cfg( not( target_os = "windows" ) ) ]
4
+ fn main ( ) -> PyResult < ( ) > {
5
+ pyo3:: prepare_freethreaded_python ( ) ;
6
+
7
+ Python :: with_gil ( |py| {
8
+ let uvloop = py. import ( "uvloop" ) ?;
9
+ uvloop. call_method0 ( "install" ) ?;
10
+
11
+ // store a reference for the assertion
12
+ let uvloop = PyObject :: from ( uvloop) ;
13
+
14
+ pyo3_asyncio:: tokio:: run ( py, async move {
15
+ // verify that we are on a uvloop.Loop
16
+ Python :: with_gil ( |py| -> PyResult < ( ) > {
17
+ assert ! ( uvloop
18
+ . as_ref( py)
19
+ . getattr( "Loop" ) ?
20
+ . downcast:: <PyType >( )
21
+ . unwrap( )
22
+ . is_instance( pyo3_asyncio:: tokio:: get_current_loop( py) ?) ?) ;
23
+ Ok ( ( ) )
24
+ } ) ?;
25
+
26
+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
27
+
28
+ println ! ( "test test_tokio_multi_thread_uvloop ... ok" ) ;
29
+ Ok ( ( ) )
30
+ } )
31
+ } )
32
+ }
33
+
34
+ #[ cfg( target_os = "windows" ) ]
35
+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ pub(super) fn test_main() {
38
38
39
39
event_loop. call_method0 ( "run_forever" ) ?;
40
40
41
- println ! ( "test test_run_forever ... ok" ) ;
42
41
Ok ( ( ) )
43
42
} )
44
43
. map_err ( |e| Python :: with_gil ( |py| dump_err ( py, e) ) )
You can’t perform that action at this time.
0 commit comments