Skip to content

Commit a0620dd

Browse files
committed
Update pyo3 to 0.25 and convert to pyo3-async-runtimes (#897)
* Update pyo3 to 0.25 and convert to pyo3-async-runtimes * Format and clippy * Simplify awaitable conversion
1 parent d5744f9 commit a0620dd

File tree

8 files changed

+155
-159
lines changed

8 files changed

+155
-159
lines changed

temporalio/bridge/Cargo.lock

Lines changed: 22 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporalio/bridge/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ async-trait = "0.1"
2121
futures = "0.3"
2222
log = "0.4"
2323
prost = "0.13"
24-
pyo3 = { version = "0.20", features = ["extension-module", "abi3-py39", "anyhow"] }
25-
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
26-
pythonize = "0.20"
24+
pyo3 = { version = "0.25", features = ["extension-module", "abi3-py39", "anyhow"] }
25+
pyo3-async-runtimes = { version = "0.25", features = ["tokio-runtime"] }
26+
pythonize = "0.25"
2727
temporal-client = { version = "0.1.0", path = "./sdk-core/client" }
2828
temporal-sdk-core = { version = "0.1.0", path = "./sdk-core/core", features = ["ephemeral-server"] }
2929
temporal-sdk-core-api = { version = "0.1.0", path = "./sdk-core/core-api" }

temporalio/bridge/src/client.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn connect_client<'a>(
8080
py: Python<'a>,
8181
runtime_ref: &runtime::RuntimeRef,
8282
config: ClientConfig,
83-
) -> PyResult<&'a PyAny> {
83+
) -> PyResult<Bound<'a, PyAny>> {
8484
let opts: ClientOptions = config.try_into()?;
8585
let runtime = runtime_ref.runtime.clone();
8686
runtime_ref.runtime.future_into_py(py, async move {
@@ -126,7 +126,11 @@ impl ClientRef {
126126
self.retry_client.get_client().set_api_key(api_key);
127127
}
128128

129-
fn call_workflow_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<&'p PyAny> {
129+
fn call_workflow_service<'p>(
130+
&self,
131+
py: Python<'p>,
132+
call: RpcCall,
133+
) -> PyResult<Bound<'p, PyAny>> {
130134
let mut retry_client = self.retry_client.clone();
131135
self.runtime.future_into_py(py, async move {
132136
let bytes = match call.rpc.as_str() {
@@ -364,12 +368,15 @@ impl ClientRef {
364368
)))
365369
}
366370
}?;
367-
let bytes: &[u8] = &bytes;
368-
Ok(Python::with_gil(|py| bytes.into_py(py)))
371+
Ok(bytes)
369372
})
370373
}
371374

372-
fn call_operator_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<&'p PyAny> {
375+
fn call_operator_service<'p>(
376+
&self,
377+
py: Python<'p>,
378+
call: RpcCall,
379+
) -> PyResult<Bound<'p, PyAny>> {
373380
use temporal_client::OperatorService;
374381

375382
let mut retry_client = self.retry_client.clone();
@@ -406,12 +413,11 @@ impl ClientRef {
406413
)))
407414
}
408415
}?;
409-
let bytes: &[u8] = &bytes;
410-
Ok(Python::with_gil(|py| bytes.into_py(py)))
416+
Ok(bytes)
411417
})
412418
}
413419

414-
fn call_cloud_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<&'p PyAny> {
420+
fn call_cloud_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<Bound<'p, PyAny>> {
415421
use temporal_client::CloudService;
416422

417423
let mut retry_client = self.retry_client.clone();
@@ -469,12 +475,11 @@ impl ClientRef {
469475
)))
470476
}
471477
}?;
472-
let bytes: &[u8] = &bytes;
473-
Ok(Python::with_gil(|py| bytes.into_py(py)))
478+
Ok(bytes)
474479
})
475480
}
476481

477-
fn call_test_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<&'p PyAny> {
482+
fn call_test_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<Bound<'p, PyAny>> {
478483
let mut retry_client = self.retry_client.clone();
479484
self.runtime.future_into_py(py, async move {
480485
let bytes = match call.rpc.as_str() {
@@ -493,12 +498,11 @@ impl ClientRef {
493498
)))
494499
}
495500
}?;
496-
let bytes: &[u8] = &bytes;
497-
Ok(Python::with_gil(|py| bytes.into_py(py)))
501+
Ok(bytes)
498502
})
499503
}
500504

501-
fn call_health_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<&'p PyAny> {
505+
fn call_health_service<'p>(&self, py: Python<'p>, call: RpcCall) -> PyResult<Bound<'p, PyAny>> {
502506
let mut retry_client = self.retry_client.clone();
503507
self.runtime.future_into_py(py, async move {
504508
let bytes = match call.rpc.as_str() {
@@ -510,8 +514,7 @@ impl ClientRef {
510514
)))
511515
}
512516
}?;
513-
let bytes: &[u8] = &bytes;
514-
Ok(Python::with_gil(|py| bytes.into_py(py)))
517+
Ok(bytes)
515518
})
516519
}
517520
}
@@ -542,13 +545,13 @@ where
542545
match res {
543546
Ok(resp) => Ok(resp.get_ref().encode_to_vec()),
544547
Err(err) => {
545-
Err(Python::with_gil(move |py| {
548+
Python::with_gil(move |py| {
546549
// Create tuple of "status", "message", and optional "details"
547550
let code = err.code() as u32;
548551
let message = err.message().to_owned();
549-
let details = err.details().into_py(py);
550-
RPCError::new_err((code, message, details))
551-
}))
552+
let details = err.details().into_pyobject(py)?.unbind();
553+
Err(RPCError::new_err((code, message, details)))
554+
})
552555
}
553556
}
554557
}

temporalio/bridge/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod testing;
88
mod worker;
99

1010
#[pymodule]
11-
fn temporal_sdk_bridge(py: Python, m: &PyModule) -> PyResult<()> {
11+
fn temporal_sdk_bridge(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
1212
// Client stuff
1313
m.add("RPCError", py.get_type::<client::RPCError>())?;
1414
m.add_class::<client::ClientRef>()?;
@@ -62,7 +62,7 @@ fn connect_client<'a>(
6262
py: Python<'a>,
6363
runtime_ref: &runtime::RuntimeRef,
6464
config: client::ClientConfig,
65-
) -> PyResult<&'a PyAny> {
65+
) -> PyResult<Bound<'a, PyAny>> {
6666
client::connect_client(py, runtime_ref, config)
6767
}
6868

@@ -77,7 +77,7 @@ fn init_runtime(telemetry_config: runtime::TelemetryConfig) -> PyResult<runtime:
7777
}
7878

7979
#[pyfunction]
80-
fn raise_in_thread(py: Python, thread_id: std::os::raw::c_long, exc: &PyAny) -> bool {
80+
fn raise_in_thread(py: Python, thread_id: std::os::raw::c_long, exc: &Bound<'_, PyAny>) -> bool {
8181
runtime::raise_in_thread(py, thread_id, exc)
8282
}
8383

@@ -86,7 +86,7 @@ fn start_dev_server<'a>(
8686
py: Python<'a>,
8787
runtime_ref: &runtime::RuntimeRef,
8888
config: testing::DevServerConfig,
89-
) -> PyResult<&'a PyAny> {
89+
) -> PyResult<Bound<'a, PyAny>> {
9090
testing::start_dev_server(py, runtime_ref, config)
9191
}
9292

@@ -95,7 +95,7 @@ fn start_test_server<'a>(
9595
py: Python<'a>,
9696
runtime_ref: &runtime::RuntimeRef,
9797
config: testing::TestServerConfig,
98-
) -> PyResult<&'a PyAny> {
98+
) -> PyResult<Bound<'a, PyAny>> {
9999
testing::start_test_server(py, runtime_ref, config)
100100
}
101101

@@ -113,6 +113,6 @@ fn new_replay_worker<'a>(
113113
py: Python<'a>,
114114
runtime_ref: &runtime::RuntimeRef,
115115
config: worker::WorkerConfig,
116-
) -> PyResult<&'a PyTuple> {
116+
) -> PyResult<Bound<'a, PyTuple>> {
117117
worker::new_replay_worker(py, runtime_ref, config)
118118
}

0 commit comments

Comments
 (0)