Async Wrapper #456
-
Hello, I would like to ask is there an Async wrapper of apsw, that can run SQLite operations asynchronously, without blocking the main thread? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
SQLite itself is not asynchronous, so any async wrapper would have to send the the work to another thread. You can do this yourself using run_in_executor with a ThreadPoolExecutor. Have you tried APSW/SQLite synchronously? SQLite is running in process and is highly optimised. The design and implementation tries to get you results as quickly as possible with the lowest time and CPU consumption. I believe that in most cases you'd find the overhead of shuffling work off to another thread dwarfs just using APSW/SQLite synchronously. My recommendation is to do things synchronously, and then do profiling to find anything that takes too much time on the main thread. For that small number of cases, use run_in_executor. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply! I will do what you recommended and use the I have not tried using APSW synchronously yet on my project. I will definitely give it a try. I used to use python's standard sqlite3 module synchronously, until the project grew bigger. |
Beta Was this translation helpful? Give feedback.
SQLite itself is not asynchronous, so any async wrapper would have to send the the work to another thread. You can do this yourself using run_in_executor with a ThreadPoolExecutor.
Have you tried APSW/SQLite synchronously? SQLite is running in process and is highly optimised. The design and implementation tries to get you results as quickly as possible with the lowest time and CPU consumption. I believe that in most cases you'd find the overhead of shuffling work off to another thread dwarfs just using APSW/SQLite synchronously.
My recommendation is to do things synchronously, and then do profiling to find anything that takes too much time on the main thread. For that small number of case…