|
51 | 51 | //! One clear disadvantage to this approach (aside from the verbose naming) is that the Rust application has to explicitly track its references to the Python event loop. In native libraries, we can't make any assumptions about the underlying event loop, so the only reliable way to make sure our conversions work properly is to store a reference to the current event loop at the callsite to use later on.
|
52 | 52 | //!
|
53 | 53 | //! ```rust
|
54 |
| -//! use pyo3::prelude::*; |
| 54 | +//! use pyo3::{wrap_pyfunction, prelude::*}; |
55 | 55 | //!
|
| 56 | +//! # #[cfg(feature = "tokio-runtime")] |
56 | 57 | //! #[pyfunction]
|
57 | 58 | //! fn sleep(py: Python) -> PyResult<&PyAny> {
|
58 | 59 | //! let current_loop = pyo3_asyncio::get_running_loop(py)?;
|
|
76 | 77 | //! })
|
77 | 78 | //! }
|
78 | 79 | //!
|
| 80 | +//! # #[cfg(feature = "tokio-runtime")] |
79 | 81 | //! #[pymodule]
|
80 | 82 | //! fn my_mod(py: Python, m: &PyModule) -> PyResult<()> {
|
81 | 83 | //! m.add_function(wrap_pyfunction!(sleep, m)?)?;
|
|
101 | 103 | //! ```rust no_run
|
102 | 104 | //! use pyo3::prelude::*;
|
103 | 105 | //!
|
| 106 | +//! # #[cfg(feature = "tokio-runtime")] |
104 | 107 | //! #[pyfunction]
|
105 | 108 | //! fn sleep(py: Python) -> PyResult<&PyAny> {
|
106 | 109 | //! // get the current event loop through task-local data
|
|
126 | 129 | //! )
|
127 | 130 | //! }
|
128 | 131 | //!
|
| 132 | +//! # #[cfg(feature = "tokio-runtime")] |
129 | 133 | //! #[pyfunction]
|
130 | 134 | //! fn wrap_sleep(py: Python) -> PyResult<&PyAny> {
|
131 | 135 | //! // get the current event loop through task-local data
|
|
152 | 156 | //! )
|
153 | 157 | //! }
|
154 | 158 | //!
|
| 159 | +//! # #[cfg(feature = "tokio-runtime")] |
155 | 160 | //! #[pymodule]
|
156 | 161 | //! fn my_mod(py: Python, m: &PyModule) -> PyResult<()> {
|
157 | 162 | //! m.add_function(wrap_pyfunction!(sleep, m)?)?;
|
|
174 | 179 | //! ```rust
|
175 | 180 | //! use pyo3::prelude::*;
|
176 | 181 | //!
|
| 182 | +//! # #[cfg(feature = "tokio-runtime")] |
177 | 183 | //! #[pyfunction]
|
178 | 184 | //! fn sleep(py: Python) -> PyResult<&PyAny> {
|
179 | 185 | //! pyo3_asyncio::tokio::future_into_py(py, async move {
|
|
189 | 195 | //! })
|
190 | 196 | //! }
|
191 | 197 | //!
|
| 198 | +//! # #[cfg(feature = "tokio-runtime")] |
192 | 199 | //! #[pyfunction]
|
193 | 200 | //! fn wrap_sleep(py: Python) -> PyResult<&PyAny> {
|
194 | 201 | //! pyo3_asyncio::tokio::future_into_py(py, async move {
|
|
202 | 209 | //! })
|
203 | 210 | //! }
|
204 | 211 | //!
|
| 212 | +//! # #[cfg(feature = "tokio-runtime")] |
205 | 213 | //! #[pymodule]
|
206 | 214 | //! fn my_mod(py: Python, m: &PyModule) -> PyResult<()> {
|
207 | 215 | //! m.add_function(wrap_pyfunction!(sleep, m)?)?;
|
@@ -391,7 +399,7 @@ fn create_future(event_loop: &PyAny) -> PyResult<&PyAny> {
|
391 | 399 | /// ```
|
392 | 400 | #[deprecated(
|
393 | 401 | since = "0.14.0",
|
394 |
| - note = "Use the pyo3_asyncio::async_std::run or pyo3_asyncio::tokio::run instead\n\t\t(see the [migration guide](https://github.com/awestlake87/pyo3-asyncio/#migrating-from-013-to-014) for more details)" |
| 402 | + note = "Use the pyo3_asyncio::async_std::run or pyo3_asyncio::tokio::run instead\n (see the [migration guide](https://github.com/awestlake87/pyo3-asyncio/#migrating-from-013-to-014) for more details)" |
395 | 403 | )]
|
396 | 404 | #[allow(deprecated)]
|
397 | 405 | pub fn with_runtime<F, R>(py: Python, f: F) -> PyResult<R>
|
|
0 commit comments