-
Rust compiler accept both versions, tested with pyo3 0.24.2: Using module's /// 🐍Lightweight OTEL span to binary converter, written in Rust🦀
#[pymodule(gil_used = false)]
fn otlp_proto(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(encode_spans, m)?)?;
m.add(
"CONTENT_TYPE",
PyString::new(m.py(), "application/x-protobuf"),
)
} Entering GIL to get /// 🐍Lightweight OTEL span to binary converter, written in Rust🦀
#[pymodule(gil_used = false)]
fn otlp_proto(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(encode_spans, m)?)?;
Python::with_gil(|py| m.add("CONTENT_TYPE", PyString::new(py, "application/x-protobuf")))
} Are both actually legal? |
Beta Was this translation helpful? Give feedback.
Answered by
mejrs
May 6, 2025
Replies: 1 comment 1 reply
-
That's fine, the gil is re-entrant so you can nest calls to |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dimaqq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's fine, the gil is re-entrant so you can nest calls to
with_gil
if you want. That said if there's already a Python token or something with apy()
method in scope, you should use that instead because it's zero cost.