@@ -60,14 +60,14 @@ use std::hash::Hash;
60
60
use std:: marker:: PhantomData ;
61
61
use std:: sync:: Mutex ;
62
62
63
+ use pyo3:: sync:: MutexExt ;
63
64
use pyo3:: { Bound , Py , Python } ;
64
65
use rustc_hash:: FxHashMap ;
65
66
66
67
use crate :: dtype:: { clone_methods_impl, Element , PyArrayDescr , PyArrayDescrMethods } ;
67
68
use crate :: npyffi:: {
68
69
PyArray_DatetimeDTypeMetaData , PyDataType_C_METADATA , NPY_DATETIMEUNIT , NPY_TYPES ,
69
70
} ;
70
- use crate :: ThreadStateGuard ;
71
71
72
72
/// Represents the [datetime units][datetime-units] supported by NumPy
73
73
///
@@ -224,13 +224,10 @@ impl TypeDescriptors {
224
224
225
225
#[ allow( clippy:: wrong_self_convention) ]
226
226
fn from_unit < ' py > ( & self , py : Python < ' py > , unit : NPY_DATETIMEUNIT ) -> Bound < ' py , PyArrayDescr > {
227
- // Detach from the runtime to avoid deadlocking on acquiring the mutex.
228
- let ts_guard = ThreadStateGuard :: new ( ) ;
229
-
230
- let mut dtypes = self . dtypes . lock ( ) . expect ( "dtype cache poisoned" ) ;
231
-
232
- // Now we hold the mutex so it's safe to re-attach to the runtime.
233
- drop ( ts_guard) ;
227
+ let mut dtypes = self
228
+ . dtypes
229
+ . lock_py_attached ( py)
230
+ . expect ( "dtype cache poisoned" ) ;
234
231
235
232
let dtype = match dtypes. get_or_insert_with ( Default :: default) . entry ( unit) {
236
233
Entry :: Occupied ( entry) => entry. into_mut ( ) ,
0 commit comments