@@ -118,31 +118,12 @@ pub fn init_runtime(telemetry_config: TelemetryConfig) -> PyResult<RuntimeRef> {
118118 }
119119 }
120120
121- let task_locals = Python :: with_gil ( |py| {
122- // Event loop is assumed to be running at this point
123- let locals = pyo3_asyncio:: TaskLocals :: with_running_loop ( py) ?. copy_context ( py) ?;
124- PyResult :: Ok ( locals)
125- } ) ?;
126-
127121 // Create core runtime which starts tokio multi-thread runtime
128122 let mut core = CoreRuntime :: new (
129123 telemetry_build
130124 . build ( )
131125 . map_err ( |err| PyValueError :: new_err ( format ! ( "Invalid telemetry config: {}" , err) ) ) ?,
132- TokioRuntimeBuilder {
133- inner : tokio:: runtime:: Builder :: new_multi_thread ( ) ,
134- lang_on_thread_start : Some ( move || {
135- // Set task locals for each thread
136- Python :: with_gil ( |_| {
137- THREAD_TASK_LOCAL . with ( |r| {
138- std:: cell:: OnceCell :: set ( r, task_locals. clone ( ) )
139- . expect ( "TaskLocals are only set once" ) ;
140- } ) ;
141- PyResult :: Ok ( ( ) )
142- } )
143- . expect ( "Setting per-thread python TaskLocals must work" ) ;
144- } ) ,
145- } ,
126+ TokioRuntimeBuilder :: default ( ) ,
146127 )
147128 . map_err ( |err| PyRuntimeError :: new_err ( format ! ( "Failed initializing telemetry: {}" , err) ) ) ?;
148129
@@ -386,12 +367,7 @@ impl TryFrom<MetricsConfig> for Arc<dyn CoreMeter> {
386367pub ( crate ) struct TokioRuntime ;
387368
388369tokio:: task_local! {
389- static TASK_LOCALS : once_cell:: unsync:: OnceCell <pyo3_asyncio:: TaskLocals >;
390- }
391-
392- thread_local ! {
393- pub ( crate ) static THREAD_TASK_LOCAL : std:: cell:: OnceCell <pyo3_asyncio:: TaskLocals > =
394- const { std:: cell:: OnceCell :: new( ) } ;
370+ static TASK_LOCALS : std:: cell:: OnceCell <pyo3_asyncio:: TaskLocals >;
395371}
396372
397373impl pyo3_asyncio:: generic:: Runtime for TokioRuntime {
@@ -414,7 +390,7 @@ impl pyo3_asyncio::generic::ContextExt for TokioRuntime {
414390 where
415391 F : Future < Output = R > + Send + ' static ,
416392 {
417- let cell = once_cell :: unsync :: OnceCell :: new ( ) ;
393+ let cell = std :: cell :: OnceCell :: new ( ) ;
418394 cell. set ( locals) . unwrap ( ) ;
419395
420396 Box :: pin ( TASK_LOCALS . scope ( cell, fut) )
0 commit comments