Skip to content

Commit 098315f

Browse files
committed
update pyo3
1 parent 0272c7e commit 098315f

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

python/src/lib.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use oxigraph::model::{BlankNode, Literal, NamedNode, NamedOrBlankNodeRef, Term};
1313
use pyo3::exceptions::PyRuntimeError;
1414
use pyo3::{
1515
prelude::*,
16-
types::{IntoPyDict, PyIterator, PyString, PyTuple},
16+
types::{IntoPyDict, PyIterator, PyString, PyStringMethods, PyTuple},
1717
};
1818
use rand::random;
1919
use std::borrow::Borrow;
@@ -254,7 +254,7 @@ fn term_to_python<'a>(
254254
#[cfg(feature = "cli")]
255255
fn run_cli(py: Python<'_>, args: Option<Vec<String>>) -> PyResult<i32> {
256256
let argv = args.unwrap_or_else(|| std::env::args().collect());
257-
let code = py.allow_threads(move || match ontoenv_cli::run_from_args(argv) {
257+
let code = py.detach(move || match ontoenv_cli::run_from_args(argv) {
258258
Ok(()) => 0,
259259
Err(err) => {
260260
eprintln!("{err}");
@@ -512,25 +512,22 @@ impl OntoEnv {
512512
// remove the owl:import statement for the 'uri' ontology
513513
transform::remove_owl_imports_graph(&mut graph, Some(&[iri.as_ref()]));
514514

515-
Python::with_gil(|_py| {
516-
for triple in graph.into_iter() {
517-
let s: Term = triple.subject.into();
518-
let p: Term = triple.predicate.into();
519-
let o: Term = triple.object.into();
515+
for triple in graph.into_iter() {
516+
let s: Term = triple.subject.into();
517+
let p: Term = triple.predicate.into();
518+
let o: Term = triple.object.into();
520519

521-
let t = PyTuple::new(
522-
py,
523-
&[
524-
term_to_python(py, &rdflib, s)?,
525-
term_to_python(py, &rdflib, p)?,
526-
term_to_python(py, &rdflib, o)?,
527-
],
528-
)?;
520+
let t = PyTuple::new(
521+
py,
522+
&[
523+
term_to_python(py, &rdflib, s)?,
524+
term_to_python(py, &rdflib, p)?,
525+
term_to_python(py, &rdflib, o)?,
526+
],
527+
)?;
529528

530-
destination_graph.getattr("add")?.call1((t,))?;
531-
}
532-
Ok::<(), PyErr>(())
533-
})?;
529+
destination_graph.getattr("add")?.call1((t,))?;
530+
}
534531
Ok(())
535532
}
536533

@@ -1283,7 +1280,7 @@ impl OntoEnv {
12831280
// Let's keep the Option return type for flexibility and adjust tests.
12841281

12851282
pub fn close(&mut self, py: Python<'_>) -> PyResult<()> {
1286-
py.allow_threads(|| {
1283+
py.detach(|| {
12871284
let inner = self.inner.clone();
12881285
let mut guard = inner.lock().unwrap();
12891286
if let Some(env) = guard.as_mut() {
@@ -1296,7 +1293,7 @@ impl OntoEnv {
12961293
}
12971294

12981295
pub fn flush(&mut self, py: Python<'_>) -> PyResult<()> {
1299-
py.allow_threads(|| {
1296+
py.detach(|| {
13001297
let inner = self.inner.clone();
13011298
let mut guard = inner.lock().unwrap();
13021299
if let Some(env) = guard.as_mut() {

0 commit comments

Comments
 (0)