|
93 | 93 | //! let locals = pyo3_async_runtimes::TaskLocals::with_running_loop(py)?.copy_context(py)?; |
94 | 94 | //! |
95 | 95 | //! // Convert the async move { } block to a Python awaitable |
96 | | -//! pyo3_async_runtimes::tokio::future_into_py_with_locals(py, locals.clone_ref(), async move { |
| 96 | +//! pyo3_async_runtimes::tokio::future_into_py_with_locals(py, locals.clone(), async move { |
97 | 97 | //! let py_sleep = Python::attach(|py| { |
98 | 98 | //! // Sometimes we need to call other async Python functions within |
99 | 99 | //! // this future. In order for this to work, we need to track the |
|
162 | 162 | //! |
163 | 163 | //! pyo3_async_runtimes::tokio::future_into_py_with_locals( |
164 | 164 | //! py, |
165 | | -//! locals.clone_ref(), |
| 165 | +//! locals.clone(), |
166 | 166 | //! // Store the current locals in task-local data |
167 | | -//! pyo3_async_runtimes::tokio::scope(locals.clone_ref(), async move { |
| 167 | +//! pyo3_async_runtimes::tokio::scope(locals.clone(), async move { |
168 | 168 | //! let py_sleep = Python::attach(|py| { |
169 | 169 | //! pyo3_async_runtimes::into_future_with_locals( |
170 | 170 | //! // Now we can get the current locals through task-local data |
|
189 | 189 | //! |
190 | 190 | //! pyo3_async_runtimes::tokio::future_into_py_with_locals( |
191 | 191 | //! py, |
192 | | -//! locals.clone_ref(), |
| 192 | +//! locals.clone(), |
193 | 193 | //! // Store the current locals in task-local data |
194 | | -//! pyo3_async_runtimes::tokio::scope(locals.clone_ref(), async move { |
| 194 | +//! pyo3_async_runtimes::tokio::scope(locals.clone(), async move { |
195 | 195 | //! let py_sleep = Python::attach(|py| { |
196 | 196 | //! pyo3_async_runtimes::into_future_with_locals( |
197 | 197 | //! &pyo3_async_runtimes::tokio::get_current_locals(py)?, |
@@ -514,10 +514,12 @@ impl TaskLocals { |
514 | 514 | pub fn context<'p>(&self, py: Python<'p>) -> Bound<'p, PyAny> { |
515 | 515 | self.context.clone_ref(py).into_bound(py) |
516 | 516 | } |
| 517 | +} |
517 | 518 |
|
| 519 | +impl Clone for TaskLocals { |
518 | 520 | /// Create a clone of the TaskLocals by incrementing the reference counters of the event loop and |
519 | 521 | /// contextvars. |
520 | | - pub fn clone_ref(&self) -> Self { |
| 522 | + fn clone(&self) -> Self { |
521 | 523 | Self { |
522 | 524 | event_loop: self.event_loop.clone(), |
523 | 525 | context: self.context.clone(), |
|
0 commit comments