watchfiles
watchfiles copied to clipboard
Resource warning when RustNotify is deleted without calling `close()`
I agree with @graingert in #164 that we should raise a resource warning just to be safe if RustNotify
isn't explicitly "closed" even though it mostly wouldn't actually be necessary since __del__
would clean up the thread.
However at the moment it seems pyo3 doesn't support the __del__
method, see https://github.com/PyO3/pyo3/issues/2479.
Once (if) pyo3 support __del__
, here is the code to add so I don't need to remember it:
pub fn __del__(&mut self, py: Python) -> PyResult<()> {
if matches!(self.watcher, WatcherEnum::None) {
Ok(())
} else {
self.close();
let resource_warning = py.import("warnings")?.getattr("ResourceWarning")?;
PyErr::warn(py, resource_warning, "RustNotify was not closed correctly", 1)
}
}