File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -20,20 +20,18 @@ use crate::TokioRuntime;
2020use datafusion:: logical_expr:: Volatility ;
2121use pyo3:: prelude:: * ;
2222use std:: future:: Future ;
23+ use std:: sync:: { Arc , OnceLock } ;
2324use tokio:: runtime:: Runtime ;
2425
2526/// Utility to get the Tokio Runtime from Python
26- pub ( crate ) fn get_tokio_runtime ( py : Python ) -> PyRef < TokioRuntime > {
27- let datafusion = py. import_bound ( "datafusion._internal" ) . unwrap ( ) ;
28- let tmp = datafusion. getattr ( "runtime" ) . unwrap ( ) ;
29- match tmp. extract :: < PyRef < TokioRuntime > > ( ) {
30- Ok ( runtime) => runtime,
31- Err ( _e) => {
27+ pub ( crate ) fn get_tokio_runtime ( _: Python ) -> Arc < TokioRuntime > {
28+ static RUNTIME : OnceLock < Arc < TokioRuntime > > = OnceLock :: new ( ) ;
29+ RUNTIME
30+ . get_or_init ( || {
3231 let rt = TokioRuntime ( tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ) ;
33- let obj: Bound < ' _ , TokioRuntime > = Py :: new ( py, rt) . unwrap ( ) . into_bound ( py) ;
34- obj. extract ( ) . unwrap ( )
35- }
36- }
32+ Arc :: new ( rt)
33+ } )
34+ . clone ( )
3735}
3836
3937/// Utility to collect rust futures with GIL released
You can’t perform that action at this time.
0 commit comments