@@ -4,7 +4,7 @@ use codex_core::protocol::{AskForApproval, EventMsg, InputItem};
44use codex_core:: { AuthManager , ConversationManager } ;
55use codex_protocol:: config_types:: SandboxMode ;
66use pyo3:: prelude:: * ;
7- use pyo3:: types:: { PyDict , PyFloat , PyList , PyModule , PyString , PyBoolMethods } ;
7+ use pyo3:: types:: { PyDict , PyFloat , PyList , PyModule , PyString } ;
88use serde_json:: Value as JsonValue ;
99use std:: path:: PathBuf ;
1010use std:: sync:: { mpsc, Arc , Mutex } ;
@@ -111,7 +111,8 @@ impl CodexEventStream {
111111 fn __iter__ ( slf : PyRefMut < ' _ , Self > ) -> PyRefMut < ' _ , Self > { slf }
112112
113113 fn __next__ ( & mut self , py : Python < ' _ > ) -> Option < Py < PyAny > > {
114- let res = py. allow_threads ( || self . rx . lock ( ) . ok ( ) ?. recv ( ) . ok ( ) ) ;
114+ // Run the blocking recv without holding the GIL
115+ let res = py. detach ( || self . rx . lock ( ) . ok ( ) ?. recv ( ) . ok ( ) ) ;
115116 match res {
116117 Some ( v) => json_to_py ( py, & v) . ok ( ) ,
117118 None => None ,
@@ -142,12 +143,12 @@ fn codex_native(_py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
142143 Ok ( ( ) )
143144}
144145
145- fn json_to_py ( py : Python < ' _ > , v : & JsonValue ) -> PyResult < PyObject > {
146+ fn json_to_py ( py : Python < ' _ > , v : & JsonValue ) -> PyResult < Py < PyAny > > {
146147 let obj = match v {
147148 JsonValue :: Null => py. None ( ) . into_pyobject ( py) ?. unbind ( ) . into_any ( ) ,
148149 JsonValue :: Bool ( b) => {
149- let iu : i64 = if * b { 1 } else { 0 } ;
150- iu . into_pyobject ( py) ?. unbind ( ) . into_any ( )
150+ let i : i64 = if * b { 1 } else { 0 } ;
151+ i . into_pyobject ( py) ?. unbind ( ) . into_any ( )
151152 }
152153 JsonValue :: Number ( n) => {
153154 if let Some ( i) = n. as_i64 ( ) {
0 commit comments