Skip to content

Commit

Permalink
Create asyncio.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
unbit committed Apr 19, 2014
1 parent b9cd336 commit 3cc8b79
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions asyncio.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
The asyncio loop engine (CPython >= 3.4)
========================================

Status: EXPERIMENTAL, lot of implications, expecially in respect to the WSGI standard

The 'asyncio' plugin exposes a loop engine built on top of the 'asyncio' CPython api (https://docs.python.org/3.4/library/asyncio.html#module-asyncio)

As uWSGI is not callback-based, you need a suspend engine (currently only the 'greenlet' one is supported) to manage the WSGI callable.

Why not mapping the WSGI callable to a coroutine ?
==================================================

The reason is pretty simple, this would break WSGI in every possible way. For this reason each uWSGI core is mapped to a greenlet (running the WSGI callable).
This greenlet registers events and coroutines in the asyncio event loop.

Callback VS coroutines
======================

When starting playing with asyncio you may get confused between callback and coroutines.

The first ones are executed when a specific event raises (for example when a file descriptor is ready for read). They are basically standard functions executed
in the main greenlet (and eventually they can swithc back control to a specific uWSGI core).

Coroutines are more complex, they are pretty near to a greenlet, but internally are really different. Your WSGI callable can spawn coroutines.

Futures and coroutines
======================

Callback example
================

0 comments on commit 3cc8b79

Please sign in to comment.