Question about asyncio and blocking operations

Frank Millman frank at chagford.com
Thu Jan 28 04:13:53 EST 2016


"Ian Kelly"  wrote in message 
news:CALwzidkr-fT6S6wH2caNaxyQvUdAw=x7XDqkqOfNRrwzwnjvOQ at mail.gmail.com...
>
> On Wed, Jan 27, 2016 at 10:14 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> > Unfortunately this doesn't actually work at present.
> > EventLoop.run_in_executor swallows the StopIteration exception and
> > just returns None, which I assume is a bug.
>
> http://bugs.python.org/issue26221
>

Thanks for that. Fascinating discussion between you and GvR.

Reading it gave me an idea.

Run the database handler in a separate thread. Use a queue.Queue to send 
requests to the handler. Use an asyncio.Queue to send results back to the 
caller, which can call 'await q.get()'.

I ran a quick test and it seems to work. What do you think?

Frank






More information about the Python-list mailing list