Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit 1964757

Browse files
committed
New page: Why using asyncio?
1 parent 6ada805 commit 1964757

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Chapter 1: First steps with asyncio
88
.. toctree::
99
:maxdepth: 2
1010

11+
why_asyncio.rst
1112
getting_started.rst
1213
hello_world.rst
1314
hello_clock.rst

why_asyncio.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
++++++++++++++++++
2+
Why using asyncio?
3+
++++++++++++++++++
4+
5+
Why asynchronous programming?
6+
=============================
7+
8+
asyncio is a library to write asynchronous applications. It is the most
9+
efficient way to implement a network server having to handle many concurrent
10+
users.
11+
12+
13+
But gevent and eventlet just work!
14+
==================================
15+
16+
Or *Why should I bother with all these extra annoying async and await
17+
keywords?*.
18+
19+
In short, asyncio adopted a radically different solution for race conditions.
20+
21+
Parallel computing using threads is hard because of race conditions. Gevent and
22+
eventlet have a similar issue using "green" (lightweight) threads.
23+
24+
Code written with asyncio is less error-prone: by just looking at the code, it
25+
is possible to identify which parts of the code are under our controls and
26+
where the event loop takes over the control flow and is able to run other tasks
27+
when our task is waiting for something.
28+
29+
gevent and eventlet are designed to hide the asynchronous programming. For
30+
non-expert, and sometimes even for experts, it is really hard to guess where
31+
the event loop is allowed to suspend the task and run other tasks in
32+
background. It is even worse. A modification in a third party library can
33+
change the behaviour of our code, introduce a new point where the task is
34+
suspended.
35+
36+
For an example, see the "Ca(sh|che Coherent) Money" section of the `Unyielding
37+
<https://glyph.twistedmatrix.com/2014/02/unyielding.html>` article (by Glyph,
38+
February, 2014).

0 commit comments

Comments
 (0)