Skip to content

Commit 44a381e

Browse files
committed
chore(native): switch to Python::detach for blocking section; simplify bool conversion; remove deprecation warnings where possible
1 parent d1098ad commit 44a381e

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ uv.lock
5151
# Ignore new markdown files by default
5252
*.md
5353

54+
# Rust build outputs
55+
target/
56+
crates/**/target/
57+
crates/**/Cargo.lock
58+
5459
# Local environment files
5560
.env
5661
.env.*

crates/codex_native/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use codex_core::protocol::{AskForApproval, EventMsg, InputItem};
44
use codex_core::{AuthManager, ConversationManager};
55
use codex_protocol::config_types::SandboxMode;
66
use pyo3::prelude::*;
7-
use pyo3::types::{PyDict, PyFloat, PyList, PyModule, PyString, PyBoolMethods};
7+
use pyo3::types::{PyDict, PyFloat, PyList, PyModule, PyString};
88
use serde_json::Value as JsonValue;
99
use std::path::PathBuf;
1010
use 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

Comments
 (0)