From fa1c8530d8e9c1e6225f4957d19f07e3d021ac93 Mon Sep 17 00:00:00 2001 From: koseki2580 Date: Fri, 10 Jan 2025 20:40:08 +0900 Subject: [PATCH] Fix data loss issue by ensuring proper locking and clearing of changes (#314) --- src/lib.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 165a4233..bbd60ebc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -328,16 +328,14 @@ impl RustNotify { } } } - let py_changes = slf - .borrow() - .changes - .lock() - .unwrap() - .to_owned() - .into_pyobject(py)? - .into_any() - .unbind(); - slf.borrow().clear(); + let py_changes = { + let borrowed = slf.borrow(); + let mut locked_changes = borrowed.changes.lock().unwrap(); + let py_changes = locked_changes.to_owned().into_pyobject(py)?.into_any().unbind(); + // Clear the changes while holding the lock + locked_changes.clear(); + py_changes + }; Ok(py_changes) }