If I want to run a long operation, I would want to do it in a thread to not block the async event-loop. asyncio provides run_in_executor() for exactly this. However, it is not clear whether my databases.Database object is safe to use in the thread, and whether there is something I can do to make it work (short of creating a brand new sa.Engine and sa.Connection with SQLAlchemy from the original URL. Or maybe one sa.Engine for the whole thread pool?)
If I want to run a long operation, I would want to do it in a thread to not block the async event-loop. asyncio provides
run_in_executor()for exactly this. However, it is not clear whether mydatabases.Databaseobject is safe to use in the thread, and whether there is something I can do to make it work (short of creating a brand newsa.Engineandsa.Connectionwith SQLAlchemy from the original URL. Or maybe onesa.Enginefor the whole thread pool?)