File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ use std::sync::RwLock;
3
3
4
4
use anyhow:: { Context , Error , Result } ;
5
5
use matchit:: Router as MatchItRouter ;
6
- use pyo3:: types:: PyAny ;
7
6
use pyo3:: { Bound , Python } ;
8
7
9
8
use crate :: routers:: Router ;
@@ -84,11 +83,15 @@ impl MiddlewareRouter {
84
83
}
85
84
86
85
pub fn get_global_middlewares ( & self , middleware_type : & MiddlewareType ) -> Vec < FunctionInfo > {
87
- self . globals
88
- . get ( middleware_type)
89
- . unwrap ( )
90
- . read ( )
91
- . unwrap ( )
92
- . to_vec ( )
86
+ Python :: with_gil ( |py| {
87
+ self . globals
88
+ . get ( middleware_type)
89
+ . unwrap ( )
90
+ . read ( )
91
+ . unwrap ( )
92
+ . iter ( )
93
+ . map ( |fi| fi. clone_with_gil ( py) )
94
+ . collect ( )
95
+ } )
93
96
}
94
97
}
Original file line number Diff line number Diff line change @@ -57,4 +57,14 @@ impl FunctionInfo {
57
57
kwargs,
58
58
}
59
59
}
60
+
61
+ pub fn clone_with_gil ( & self , py : Python ) -> Self {
62
+ Self {
63
+ handler : self . handler . clone_ref ( py) ,
64
+ is_async : self . is_async ,
65
+ number_of_params : self . number_of_params ,
66
+ args : self . args . clone_ref ( py) ,
67
+ kwargs : self . kwargs . clone_ref ( py) ,
68
+ }
69
+ }
60
70
}
You can’t perform that action at this time.
0 commit comments