Debian Codegraph @

pytests/test_tokio_current_thread_uvloop.rs

raw symbols SCIP
1 #[cfg(not(target_os = "windows"))]
2 fn main() -> pyo3::PyResult<()> {
3 use pyo3::{prelude::*, types::PyType};
4
5 Python::initialize();
6
7 let mut builder = tokio::runtime::Builder::new_current_thread();
8 builder.enable_all();
9
10 pyo3_async_runtimes::tokio::init(builder);
11 std::thread::spawn(move || {
12 pyo3_async_runtimes::tokio::get_runtime().block_on(futures_util::future::pending::<()>());
13 });
14
15 Python::attach(|py| {
16 // uvloop not supported on the free-threaded build yet
17 // https://github.com/MagicStack/uvloop/issues/642
18 let sysconfig = py.import("sysconfig")?;
19 let is_freethreaded = sysconfig.call_method1("get_config_var", ("Py_GIL_DISABLED",))?;
20 if is_freethreaded.is_truthy()? {
21 return Ok(());
22 }
23
24 // uvloop not yet supported on 3.14
25 if py.version_info() >= (3, 14) {
26 return Ok(());
27 }
28
29 let uvloop = py.import("uvloop")?;
30 uvloop.call_method0("install")?;
31
32 // store a reference for the assertion
33 let uvloop: Py<PyAny> = uvloop.into();
34
35 pyo3_async_runtimes::tokio::run(py, async move {
36 // verify that we are on a uvloop.Loop
37 Python::attach(|py| -> PyResult<()> {
38 assert!(pyo3_async_runtimes::tokio::get_current_loop(py)?
39 .is_instance(uvloop.bind(py).getattr("Loop")?.cast::<PyType>().unwrap())?);
40 Ok(())
41 })?;
42
43 tokio::time::sleep(std::time::Duration::from_secs(1)).await;
44
45 println!("test test_tokio_current_thread_uvloop ... ok");
46 Ok(())
47 })
48 })
49 }
50
51 #[cfg(target_os = "windows")]
52 fn main() {}