@@ -66,13 +66,11 @@ where
6666 for < ' py > <T as IntoPyObject < ' py > >:: Error : std:: fmt:: Debug ,
6767{
6868 if function. is_async {
69- // Single GIL acquisition for async functions
7069 let output: Py < PyAny > = Python :: with_gil ( |py| {
7170 pyo3_async_runtimes:: tokio:: into_future ( get_function_output ( function, py, input) ?)
7271 } ) ?
7372 . await ?;
7473
75- // Reuse the same GIL acquisition for extraction
7674 Python :: with_gil ( |py| -> Result < MiddlewareReturn > {
7775 // Try response extraction first, then request
7876 match output. extract :: < Response > ( py) {
@@ -84,12 +82,10 @@ where
8482 }
8583 } )
8684 } else {
87- // Single GIL acquisition for sync functions - do everything in one block
8885 Python :: with_gil ( |py| -> Result < MiddlewareReturn > {
8986 let output = get_function_output ( function, py, input) ?;
9087 debug ! ( "Middleware output: {:?}" , output) ;
9188
92- // Extract within the same GIL acquisition
9389 match output. extract :: < Response > ( ) {
9490 Ok ( response) => Ok ( MiddlewareReturn :: Response ( response) ) ,
9591 Err ( _) => match output. extract :: < Request > ( ) {
@@ -107,17 +103,14 @@ pub async fn execute_http_function(
107103 function : & FunctionInfo ,
108104) -> PyResult < Response > {
109105 if function. is_async {
110- // Single GIL acquisition for async setup
111106 let output = Python :: with_gil ( |py| {
112107 let function_output = get_function_output ( function, py, request) ?;
113108 pyo3_async_runtimes:: tokio:: into_future ( function_output)
114109 } ) ?
115110 . await ?;
116111
117- // Single GIL acquisition for extraction
118112 Python :: with_gil ( |py| -> PyResult < Response > { output. extract ( py) } )
119113 } else {
120- // Single GIL acquisition for entire sync execution
121114 Python :: with_gil ( |py| -> PyResult < Response > {
122115 get_function_output ( function, py, request) ?. extract ( )
123116 } )
0 commit comments