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

Can object.__del__ be removed from the MicroPython stubs? #628

Open
Josverl opened this issue Dec 8, 2024 · 0 comments
Open

Can object.__del__ be removed from the MicroPython stubs? #628

Josverl opened this issue Dec 8, 2024 · 0 comments

Comments

@Josverl
Copy link
Owner

Josverl commented Dec 8, 2024

Or decorated with a warning ?

If you need to make objects that free/stop/cleanup resources when no longer used, the best way to do it is with a context manager. This will ensure that things are cleaned up, even if an exception occurs. The second best way is to make a close() method and ensure that close() is called when the object is no longer needed.

__del__ is non-deterministic by definition, so is not really the right tool for that job. See https://github.com/orgs/micropython/discussions/14287 as an example of how __del__ can be problematic in this way.

Originally posted by @dlech in micropython/micropython#1878 (comment)

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