Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non send types like PyDateTime #37

Open
glennpierce opened this issue Jul 21, 2021 · 2 comments
Open

Non send types like PyDateTime #37

glennpierce opened this issue Jul 21, 2021 · 2 comments

Comments

@glennpierce
Copy link

If I have a pyfunction like

#[pyfunction]
fn get_data(py: Python, sensor_id: i32, start_datetime: &PyDateTime) -> PyResult<PyObject>  ...

that calls into_coroutine for a async block I get

F: Future<Output = PyResult> + Send + 'static,
| ---- required by this bound in pyo3_asyncio::tokio::into_coroutine
|
= help: within PyDateTime, the trait Sync is not implemented for UnsafeCell<pyo3::ffi::PyObject>

Can values that are not send be wrapped in Arc or something.
What is the usual way of dealing with that.

@glennpierce
Copy link
Author

Actually I converted it to a DateTime outside the into_coroutine which solves the issue.
I guess there may be times where that won't do so original question may stand.

Thanks

@awestlake87
Copy link
Owner

You might get this error when your future is capturing a reference to a PyO3 object like &PyDateTime when the real issue is that the future will not be able to capture that reference due to lifetime issues. Usually, the best thing to do is convert that &PyDateTime into a Py<PyDateTime> so it can be passed around like an Arc with the `'static' lifetime.

If that doesn't fix your Send issues, there are !Send variants of into_coroutine called local_future_into_py although they do have some caveats mentioned in this thread #23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants