Skip to content

Commit

Permalink
fix: fix scout deadlock
Browse files Browse the repository at this point in the history
Releasing GIL in Scout destructor prevents the deadlock.
  • Loading branch information
wyfo committed Apr 18, 2024
1 parent b70096e commit fd6644c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl _PullSubscriber {
}

#[pyclass(subclass)]
pub struct _Scout(Scout<()>);
pub struct _Scout(Option<Scout<()>>);

#[pyfunction]
pub fn scout(
Expand All @@ -315,7 +315,13 @@ pub fn scout(
let config = config.and_then(|c| c.0.clone().take()).unwrap_or_default();
let scout = zenoh::scout(what, config).with(callback).res_sync();
match scout {
Ok(scout) => Ok(_Scout(scout)),
Ok(scout) => Ok(_Scout(Some(scout))),
Err(e) => Err(e.to_pyerr()),
}
}

impl Drop for _Scout {
fn drop(&mut self) {
Python::with_gil(|gil| gil.allow_threads(|| drop(self.0.take())));
}
}

0 comments on commit fd6644c

Please sign in to comment.