Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in RustNotify causing RuntimeError: Already borrowed on exit/signal #221

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ impl RustNotify {
}

pub fn watch(
&self,
slf: &PyCell<Self>,
py: Python,
debounce_ms: u64,
step_ms: u64,
timeout_ms: u64,
stop_event: PyObject,
) -> PyResult<PyObject> {
if matches!(self.watcher, WatcherEnum::None) {
if matches!(slf.borrow().watcher, WatcherEnum::None) {
return Err(PyRuntimeError::new_err("RustNotify watcher closed"));
}
let stop_event_is_set: Option<&PyAny> = match stop_event.is_none(py) {
Expand All @@ -257,27 +257,27 @@ impl RustNotify {
match py.check_signals() {
Ok(_) => (),
Err(_) => {
self.clear();
slf.borrow().clear();
return Ok("signal".to_object(py));
}
};

if let Some(error) = self.error.lock().unwrap().as_ref() {
self.clear();
if let Some(error) = slf.borrow().error.lock().unwrap().as_ref() {
slf.borrow().clear();
return wf_error!(error.clone());
}

if let Some(is_set) = stop_event_is_set {
if is_set.call0()?.is_true()? {
if self.debug {
if slf.borrow().debug {
eprintln!("stop event set, stopping...");
}
self.clear();
slf.borrow().clear();
return Ok("stop".to_object(py));
}
}

let size = self.changes.lock().unwrap().len();
let size = slf.borrow().changes.lock().unwrap().len();
if size > 0 {
if size == last_size {
break;
Expand All @@ -294,13 +294,13 @@ impl RustNotify {
}
} else if let Some(max_time) = max_timeout_time {
if SystemTime::now() > max_time {
self.clear();
slf.borrow().clear();
return Ok("timeout".to_object(py));
}
}
}
let py_changes = self.changes.lock().unwrap().to_object(py);
self.clear();
let py_changes = slf.borrow().changes.lock().unwrap().to_object(py);
slf.borrow().clear();
Ok(py_changes)
}

Expand Down