Skip to content

Don't close drivers & sessions in finalizer #1183

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

robsdedude
Copy link
Member

@robsdedude robsdedude commented May 16, 2025

No longer implicitly closing drivers and sessions in __del__() (finalizer/destructor). Make sure to call .close() on them explicitly or use them in a with statement.

A deprecation warning has been emitted in such cases before.

Relying on __del__ leads to hard to follow control flow and can result in surprising behavior as there is no guarantee when that the finalizer will be called if ever. A ResourceWarning is emitted instead.

See also: https://docs.python.org/3/reference/datamodel.html#object.__del__

Copy link
Contributor

@StephenCathcart StephenCathcart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@robsdedude robsdedude enabled auto-merge (squash) May 19, 2025 13:42
@robsdedude robsdedude changed the title Don't close drivers & session in finalizer Don't close drivers & sessions in finalizer May 19, 2025
@robsdedude robsdedude disabled auto-merge May 19, 2025 13:42
@robsdedude robsdedude enabled auto-merge (squash) May 19, 2025 13:43
@robsdedude robsdedude merged commit 0e4d772 into neo4j:6.x May 19, 2025
20 checks passed
@robsdedude robsdedude deleted the no-close-on-del branch May 19, 2025 14:43
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

Successfully merging this pull request may close these issues.

2 participants