[Python-ideas] async/await in Python (C API ?)
Yury Selivanov
yselivanov.ml at gmail.com
Mon Apr 20 15:40:00 CEST 2015
Hi Marc-Andre,
On 2015-04-20 9:18 AM, M.-A. Lemburg wrote:
> Hi Yury,
>
> do you have any plans of also exposing an easy to use C API
> for async and await ?
>
> I think this would be useful to e.g. implement asynchronous
> database access. Most of those adapters are written in C and
> need so a C API would help a lot with this.
I think one way to have a convenient C API is to implement
a Future-like object in C -- an object with __await__ method
that should return an iterator, which should also be
implemented in C and provide a way to attach callback
or to *pipeline* C functions.
This way C code should seamlessly integrate with asyncio.
I doubt that we have time to include this kind of API in
the PEP, but it can be developed as a separate library.
Your thoughts?
>
> A problem I ran to with e.g. gevent is that it's not easy
> to use the available async APIs from C, even less so for
> systems like the ODBC API which require the use of polling
> for async processing and which don't give you access to e.g.
> tap into long running parts of the communication (sockets, etc.)
> which gevent does at the Python level.
>
> Thanks,
The other problem is that asyncio itself is written in
Python, so it won't be easy to use it from C. I think
it might be a good idea to speed up asyncio by implementing
core event loop and selectors in C and to have an easy
to use C API on top of that, but it's not in the scope
of the PEP.
Thanks,
Yury
More information about the Python-ideas
mailing list