Close connections opened by other threads in AutoImport.close() - #888
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
AutoImport opens one SQLite connection per thread, but close() only closed the one of the calling thread, so connections made by worker threads were left open (ResourceWarning: unclosed database). Keep track of every thread's connection and close them all in close(). Connections of threads that have finished are closed when a new one is opened, so the list doesn't grow in long running processes. Fixes python-rope#886
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
AutoImportopens one SQLite connection per thread, butclose()only closed the connection of the thread calling it. Connections opened by worker threads stayed open until they were garbage collected, which shows up asResourceWarning: unclosed databaseon Python 3.13+.This keeps track of each thread's connection and closes all of them in
close(). Connections of threads that have already finished are closed when a new thread opens its connection, so the list doesn't keep growing in long running processes.To be able to close them from another thread, connections are now created with
check_same_thread=False. Each thread still only uses its own connection.Note: most of the
unclosed databasewarnings in the test suite come from tests that create anAutoImportand never callclose(), so this change doesn't remove those.Fixes #886
Checklist (delete if not relevant):