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