Question about asyncio and blocking operations

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 28 19:20:50 EST 2016


On Jan 28, 2016 3:07 PM, "Maxime Steisel" <maximesteisel at gmail.com> wrote:
>
> But it is a pretty strange idea to call two fetch*() method concurrently
anyways.

If you want to process rows concurrently and aren't concerned with
processing them in order, it may be attractive to create multiple threads /
coroutines, pass the cursor to each, and let them each call fetchmany
independently. I agree this is a bad idea unless you use a lock to isolate
the calls or are certain that you'll never use a dbapi implementation with
threadsafety < 3.

I pointed it out because the wrapper makes it less obvious that multiple
threads are involved; one could naively assume that the separate calls are
isolated by the event loop.



More information about the Python-list mailing list