-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure iterable gets closed in asyncmapper
In `AsyncMapper`, generators are executed on a separate thread. However, if an exception occurs, the `__exit__` method gets executed in the main thread. This can lead to issues with SQLite. Specifically, attempting to close a connection outside the thread where it was created results in the following error: ```console sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145530425344 and this is thread id 140704344640320. ``` This PR modifies `AsyncMapper` to ensure that `__exit__` is executed in the same thread where the generator runs. Additionally, since the main thread might still attempt to close the generator, I have added safeguards to avoid calling `sqlite.Connection.close()` more than once. The behavior of the main thread calling `__exit__` is beyond `AsyncMapper`'s control, as it accepts arbitrary `Iterable` inputs.
- Loading branch information
Showing
4 changed files
with
41 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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