Emit warning if connection is deleted before it is closed #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
An unclosed
aiosqlite.Connectioncauses the interpreter to stay alive even after the main thread exits.This PR fixes it by
Connectionowns a thread (instead of be a thread)Connectionclass and only receives the shared request queue__del__, which emits aResourceWarningif the connection is still active, and attempts to stop the worker thread.Changes 1 and 2 makes it so that the thread does not hold a reference to the entire connection object, which allows the object to be garbage collected when unused (unless some other thing is causing a reference cycle e.g. exceptions) and
__del__called.Unlike #308, the worker thread is not daemonic, so there shouldn't be a risk of the thread being shut down before transactions are finalized.
This is likely a breaking change, since
Connectionis not a subclass ofThreadanymore.Fixes: #290 #299