@@ -28,7 +28,7 @@ impl CoreBPE {
2828
2929    #[ pyo3( name = "encode_ordinary" ) ]  
3030    fn  py_encode_ordinary ( & self ,  py :  Python ,  text :  & str )  -> Vec < Rank >  { 
31-         py. allow_threads ( || self . encode_ordinary ( text) ) 
31+         py. detach ( || self . encode_ordinary ( text) ) 
3232    } 
3333
3434    #[ pyo3( name = "encode" ) ]  
@@ -38,7 +38,7 @@ impl CoreBPE {
3838        text :  & str , 
3939        allowed_special :  HashSet < PyBackedStr > , 
4040    )  -> PyResult < Vec < Rank > >  { 
41-         py. allow_threads ( || { 
41+         py. detach ( || { 
4242            let  allowed_special:  HashSet < & str >  =
4343                allowed_special. iter ( ) . map ( |s| s. as_ref ( ) ) . collect ( ) ; 
4444            match  self . encode ( text,  & allowed_special)  { 
@@ -54,7 +54,7 @@ impl CoreBPE {
5454        text :  & str , 
5555        allowed_special :  HashSet < PyBackedStr > , 
5656    )  -> PyResult < Py < PyAny > >  { 
57-         let  tokens_res = py. allow_threads ( || { 
57+         let  tokens_res = py. detach ( || { 
5858            let  allowed_special:  HashSet < & str >  =
5959                allowed_special. iter ( ) . map ( |s| s. as_ref ( ) ) . collect ( ) ; 
6060            self . encode ( text,  & allowed_special) 
@@ -70,7 +70,7 @@ impl CoreBPE {
7070    } 
7171
7272    fn  _encode_bytes ( & self ,  py :  Python ,  bytes :  & [ u8 ] )  -> Vec < Rank >  { 
73-         py. allow_threads ( || { 
73+         py. detach ( || { 
7474            match  std:: str:: from_utf8 ( bytes)  { 
7575                // Straightforward case 
7676                Ok ( text)  => self . encode_ordinary ( text) , 
@@ -121,7 +121,7 @@ impl CoreBPE {
121121        text :  & str , 
122122        allowed_special :  HashSet < PyBackedStr > , 
123123    )  -> PyResult < ( Vec < Rank > ,  Py < PyList > ) >  { 
124-         let  ( tokens,  completions) :  ( Vec < Rank > ,  HashSet < Vec < Rank > > )  = py. allow_threads ( || { 
124+         let  ( tokens,  completions) :  ( Vec < Rank > ,  HashSet < Vec < Rank > > )  = py. detach ( || { 
125125            let  allowed_special:  HashSet < & str >  =
126126                allowed_special. iter ( ) . map ( |s| s. as_ref ( ) ) . collect ( ) ; 
127127            self . _encode_unstable_native ( text,  & allowed_special) 
@@ -155,7 +155,7 @@ impl CoreBPE {
155155
156156    #[ pyo3( name = "decode_bytes" ) ]  
157157    fn  py_decode_bytes ( & self ,  py :  Python ,  tokens :  Vec < Rank > )  -> Result < Py < PyBytes > ,  PyErr >  { 
158-         match  py. allow_threads ( || self . decode_bytes ( & tokens) )  { 
158+         match  py. detach ( || self . decode_bytes ( & tokens) )  { 
159159            Ok ( bytes)  => Ok ( PyBytes :: new ( py,  & bytes) . into ( ) ) , 
160160            Err ( e)  => Err ( pyo3:: exceptions:: PyKeyError :: new_err ( format ! ( "{}" ,  e) ) ) , 
161161        } 
0 commit comments