File tree Expand file tree Collapse file tree 3 files changed +278
-110
lines changed
Expand file tree Collapse file tree 3 files changed +278
-110
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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 } ) ;
You can’t perform that action at this time.
0 commit comments