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

Resource warning when RustNotify is deleted without calling close() #166

Open
samuelcolvin opened this issue Jun 25, 2022 · 0 comments
Open

Comments

@samuelcolvin
Copy link
Owner

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 PyO3/pyo3#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)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant