[DB-SIG] asyncio support

M.-A. Lemburg mal at python.org
Tue Nov 12 11:41:02 CET 2013


On 11.11.2013 10:43, INADA Naoki wrote:
> I think having definition about what method returns Future is good.
> 
> For example:
> 
> con = yield from pymysql.connect_async(...)  # connection may cause
> cur = con.cursor()  # cursor creation should done without asyncio
> yield from cur.execute("...")  # execute may use asyncio
> row = yield from cur.fetchone()  # fetch also uses asyncio
> 
> for row in cur:  # raises NotImplementedError

This can already be implemented using e.g. gevent, provided the
client side is implemented in Python (and gevent can thus patch
the socket module).

For native C client libs, this will not easily be possible, since
the Python wrapper will typically not get access to the underlying
socket logic, so you have to rely on native async support in the
library.

E.g. ODBC has limited support for this, but uses an active
polling mechanism, so callbacks won't work and I'm not
sure Futures would directly. You would have to hook up the
polling with the async event loop.

What always works is using threads as a way to let other
code continue to run. .execute() and .fetch...() usually release
the GIL for this purpose.

> On Mon, Nov 11, 2013 at 5:49 AM, Tony Locke <tlocke at tlocke.org.uk> wrote:
> 
>> What sort of thing do you have in mind? Perhaps something where the
>> execute() method returns immediately, and a callback function is called
>> when the query is complete?
>>
>> This could be implemented in a library on top of DB-API. But should it be
>> part of the spec?
>>
>> Cheers,
>>
>> Tony.
>>
>>
>> On 25 October 2013 08:27, INADA Naoki <songofacandy at gmail.com> wrote:
>>
>>> Does someone consider DB-API for asyncio?
>>>
>>>
>>> --
>>> INADA Naoki  <songofacandy at gmail.com>
>>>
>>> _______________________________________________
>>> DB-SIG maillist  -  DB-SIG at python.org
>>> https://mail.python.org/mailman/listinfo/db-sig
>>>
>>>
>>
>> _______________________________________________
>> DB-SIG maillist  -  DB-SIG at python.org
>> https://mail.python.org/mailman/listinfo/db-sig
>>
>>
> 
> 
> 
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> https://mail.python.org/mailman/listinfo/db-sig
> 

-- 
Marc-Andre Lemburg
Director
Python Software Foundation
http://www.python.org/psf/


More information about the DB-SIG mailing list