From 25cee1249b7ecf7820fdd592a8848abe6163ba4e Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Mon, 16 Sep 2024 21:01:29 -0400 Subject: [PATCH] Fix python async --- icechunk-python/src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/icechunk-python/src/lib.rs b/icechunk-python/src/lib.rs index 43d08191..4417c598 100644 --- a/icechunk-python/src/lib.rs +++ b/icechunk-python/src/lib.rs @@ -49,14 +49,24 @@ impl PyIcechunkStore { Ok(()) } - pub async fn commit( - &mut self, + pub fn commit<'py>( + &'py mut self, + py: Python<'py>, update_branch_name: String, message: String, - ) -> PyIcechunkStoreResult { - let (oid, _version) = - self.store.write().await.commit(&update_branch_name, &message).await?; - Ok(String::from(&oid)) + ) -> PyResult> { + let store = Arc::clone(&self.store); + + // The commit mechanism is async and calls tokio::spawn so we need to use the + // pyo3_asyncio_0_21::tokio helper to run the async function in the tokio runtime + pyo3_asyncio_0_21::tokio::future_into_py(py, async move { + let mut writeable_store = store.write().await; + let (oid, _version) = writeable_store + .commit(&update_branch_name, &message) + .await + .map_err(PyIcechunkStoreError::from)?; + Ok(String::from(&oid)) + }) } pub async fn empty(&self) -> PyIcechunkStoreResult {