Skip to content

Don't close drivers & sessions in finalizer - #1183

Merged
robsdedude merged 2 commits into
neo4j:6.xfrom
robsdedude:no-close-on-del
May 19, 2025
Merged

robsdedude merged 2 commits into
neo4j:6.xfrom
robsdedude:no-close-on-del

Conversation

@robsdedude

@robsdedude robsdedude commented May 16, 2025 •

Copy link
Copy Markdown
Member

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__

@StephenCathcart StephenCathcart left a comment

Copy link
Copy Markdown
Contributor

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
@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