Skip to content

Commit f97f42f

Browse files
committed
Move some with_gil calls outside of tokio event loop
1 parent 5ce66d1 commit f97f42f

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/generic.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,11 @@ where
596596
let future_tx1: Py<PyAny> = py_fut.clone().into();
597597
let future_tx2 = future_tx1.clone_ref(py);
598598

599-
R::spawn(async move {
600-
let locals2 = Python::attach(|py| locals.clone_ref(py));
599+
let (locals2, locals3) = Python::attach(|py| (locals.clone_ref(py), locals.clone_ref(py)));
601600

601+
R::spawn(async move {
602602
if let Err(e) = R::spawn(async move {
603-
let result = R::scope(
604-
Python::attach(|py| locals2.clone_ref(py)),
605-
Cancellable::new_with_cancel_rx(fut, cancel_rx),
606-
)
607-
.await;
603+
let result = R::scope(locals2, Cancellable::new_with_cancel_rx(fut, cancel_rx)).await;
608604

609605
Python::attach(move |py| {
610606
if cancelled(future_tx1.bind(py))
@@ -615,7 +611,7 @@ where
615611
}
616612

617613
let _ = set_result(
618-
&locals2.event_loop(py),
614+
&locals3.event_loop(py),
619615
future_tx1.bind(py),
620616
result.and_then(|val| val.into_py_any(py)),
621617
)

0 commit comments

Comments
 (0)