Skip to content

Commit 8637177

Browse files
committed
refactor: Limit mutex lock scope in get_graph method to reduce deadlock risk
1 parent 0380ab0 commit 8637177

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

python/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,16 @@ impl OntoEnv {
419419
let iri = NamedNode::new(uri.to_string())
420420
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))?;
421421
println!("Locking inner");
422-
let inner = self.inner.clone();
423-
let env = inner.lock().unwrap();
424-
println!("Getting graph by name");
425-
let graph = env
426-
.get_graph_by_name(iri.as_ref())
427-
.map_err(anyhow_to_pyerr)?;
428-
println!("Got graph by name");
422+
let graph = {
423+
let inner = self.inner.clone();
424+
let env = inner.lock().unwrap();
425+
println!("Getting graph by name");
426+
let graph = env
427+
.get_graph_by_name(iri.as_ref())
428+
.map_err(anyhow_to_pyerr)?;
429+
println!("Got graph by name");
430+
graph
431+
};
429432
let res = rdflib.getattr("Graph")?.call0()?;
430433
for triple in graph.into_iter() {
431434
let s: Term = triple.subject.into();

0 commit comments

Comments
 (0)