The ElectrumSV database access is asynchronous with optional callbacks on completion or error. All database writes are done in a single writer thread for Sqlite specific reasons. The asynchronous with callback approach mainly a simple first approach since often database is done from within the Qt UI thread and we do not ever want to block that or the whole UI becomes unresponsive.
We want to transition the database access to be coroutine based where possible, and this means we need to block the current coroutine, post the database transaction to execute to the writer thread, and then post the result or exception back to the blocked coroutine in the original thread. Then the coroutine either resumes returning the result, or has raised out of it the exception that happened in the writer thread.
The question is, what standard Python thingzies can be combined to do this while avoiding writing your own custom Python thingzies. I expect that the core of it can be done by wrapping the transaction database calls in a Future, and then it's just a matter of blocking the coroutine on an non-threadsafe asyncio.Event. Maybe there's an existing way?
-- rt12
The ElectrumSV database access is asynchronous with optional callbacks on completion or error. All database writes are done in a single writer thread for Sqlite specific reasons. The asynchronous with callback approach mainly a simple first approach since often database is done from within the Qt UI thread and we do not ever want to block that or the whole UI becomes unresponsive.
We want to transition the database access to be coroutine based where possible, and this means we need to block the current coroutine, post the database transaction to execute to the writer thread, and then post the result or exception back to the blocked coroutine in the original thread. Then the coroutine either resumes returning the result, or has raised out of it the exception that happened in the writer thread.
The question is, what standard Python thingzies can be combined to do this while avoiding writing your own custom Python thingzies. I expect that the core of it can be done by wrapping the transaction database calls in a Future, and then it's just a matter of blocking the coroutine on an non-threadsafe asyncio.Event. Maybe there's an existing way?
-- rt12