Jump to: navigation, search

Oslo/blueprints/asyncio

< Oslo
Revision as of 14:17, 21 January 2014 by Victor Stinner (talk | contribs) (Replace eventlet with asyncio in Olso Messaging)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Authors

  • Victor Stinner - victor.stinner@enovance.com

Rationale

The Enovance company is working actively on porting OpenStack on Python 3, see the status on the Python 3 page. Eventlet dependency blocks the portage because it is not yet compatible with Python 3. Even if it would be available, we would like to get ride of eventlet for the reasons explained below.

We choose to start the work in the Olso Messaging project because its design allows to use different "executor drivers", a function to run a task asynchronously, and because Olso Messaging is a core component.

The idea is to add a new asyncio executor to Olso Messaging. At the beginning, asyncio will reuse greenlet event loop and of its own event loop. If an OpenStack daemon doesn't use eventlet anymore, it will be possible to use asyncio event loops.

Background: asynchronous programming in OpenStack

Past: Twisted Current: eventlet

What's wrong with eventlet?

greenlet: http://greenlet.readthedocs.org/ eventlet: http://eventlet.net/

Why using asyncio and not yet another asynchronous library?

The asyncio module has be designed as a superset of existing libraries: Twisted, Tornado, gevent, eventlet, etc. The design is the PEP 3156 written by Guido van Rossum who also wrote the Python language. The PEP has been written with the help of various developers and the design reuses many good ideas of existing libraries. Asyncio offers a nice syntax for coroutines using the new "yield from" syntax of Python 3.3.

The PEP 3156 has been accepted and asyncio is part of the standard library of Python 3.4. For Python 3.3, the third party project Tulip can be used. For Python 2.6 and 2.7, Enovance ported asyncio on Python 2 as a new Trollius project which is based on Tulip. Trollius uses "yield" instead of "yield from" and "return x" must be replaced with "raise Return(x)". Enovance also wrote the documentation of the asyncio module: asyncio – Asynchronous I/O, event loop, coroutines and tasks.

Smooth integration of asyncio in Olso Messaging: greenio

greenio: https://github.com/1st1/greenio/

The greenio project allows to "plug" asyncio in eventlet: it is an event loop compatible with asyncio but using greenlet functions like greenlet.switch(). So it becomes possible to use the new asyncio API, but existing OpenStack code doesn't need to be changed and will still use eventlet.