-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Milestone
Description
Follow-up from #173.
Currently, the aiosqlite connection used by SQLiteBackend will only close automatically if used with the CachedSession contextmanager. Otherwise, the Thread object used by aiosqlite remains open and causes the program to hang (unlike the stdlib sqlite3 module, which works fine with leaving connections open).
Workarounds
Either use the contextmanager:
async with CachedSession(cache=SQLiteBackend()) as session:
...Or explicitly call close():
session = CachedSession(cache=SQLiteBackend())
...
session.close()Options
- Reopen and close connection for every request
- Reliable, but comes with a performance hit.
- Schedule close using
SQLiteBackend.__del__()(suggested here)- As @aaraney mentioned, this isn't guaranteed to complete before the event loop closes.
- Subclass and modify
aiosqlite.Connection.run()to accept a signal to immediately close without blocking the event loop or needing to be scheduled - Various other means of forcing the thread to close (like raising an exception inside the thread or messing with its internal queue)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request