Skip to content
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -20,20 +20,16 @@ use crate::TokioRuntime;
20
20
use datafusion:: logical_expr:: Volatility ;
21
21
use pyo3:: prelude:: * ;
22
22
use std:: future:: Future ;
23
+ use std:: sync:: { Arc , OnceLock } ;
23
24
use tokio:: runtime:: Runtime ;
24
25
25
26
/// 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) => {
32
- 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
- }
27
+ pub ( crate ) fn get_tokio_runtime ( _: Python ) -> Arc < TokioRuntime > {
28
+ static RUNTIME : OnceLock < Arc < TokioRuntime > > = OnceLock :: new ( ) ;
29
+ RUNTIME . get_or_init ( || {
30
+ let rt = TokioRuntime ( tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ) ;
31
+ Arc :: new ( rt)
32
+ } ) . clone ( )
37
33
}
38
34
39
35
/// Utility to collect rust futures with GIL released
You can’t perform that action at this time.
0 commit comments