Skip to content

Conversation

@beer-psi
Copy link
Contributor

@beer-psi beer-psi commented Sep 13, 2025

Description

An unclosed aiosqlite.Connection causes the interpreter to stay alive even after the main thread exits.

This PR fixes it by

  • Making the Connection owns a thread (instead of be a thread)
  • The worker thread function is moved out of the Connection class and only receives the shared request queue
  • Implement __del__, which emits a ResourceWarning if 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 Connection is not a subclass of Thread anymore.

Fixes: #290 #299

@amyreese
Copy link
Member

Thank you for working on this. Would you be able to rebase your changes onto latest main? I'd like to get this included in the next release.

@beer-psi
Copy link
Contributor Author

I've rebased my changes against latest main.

@amyreese amyreese merged commit 1cd60ad into omnilib:main Dec 13, 2025
18 checks passed
@amyreese
Copy link
Member

Thank you!

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.

Aiosqlite leaves thread hanging

2 participants