Skip to content

Commit 0053900

Browse files
committed
optimize and resolve issues
1 parent de42ba2 commit 0053900

File tree

3 files changed

+278
-110
lines changed

3 files changed

+278
-110
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ def add(a, b):
548548
);
549549
}
550550

551-
#[cfg(feature = "pyo3")]
552551
#[tokio::test]
553552
async fn test_run_with_async_function() {
554553
let executor = PyRunner::new();

src/pyo3_runner.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ async fn handle_call_async_function(
152152
responder: oneshot::Sender<Result<Value, String>>,
153153
) {
154154
let result = Python::attach(|py| {
155+
// Note: This approach creates a new asyncio event loop for each async call,
156+
// which can be inefficient for a high volume of calls. It ensures that each
157+
// call is isolated but does not share an event loop for concurrent execution
158+
// on the Python side.
155159
let func = func.bind(py);
156160
let t_args = vec_to_py_tuple(&py, args)?;
157161
let coroutine = func.call1(t_args)?;
158162

159163
let asyncio = py.import("asyncio")?;
160-
let loop_obj = asyncio.call_method0("new_event_loop")?;
161-
asyncio.call_method1("set_event_loop", (loop_obj.clone(),))?;
162-
let result = loop_obj.call_method1("run_until_complete", (coroutine,))?;
163-
loop_obj.call_method0("close")?;
164+
let result = asyncio.call_method1("run", (coroutine,))?;
164165

165166
py_any_to_json(&result)
166167
});

0 commit comments

Comments
 (0)