Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 39 lines (30 sloc) 1.719 kb
b136163 started a doc on how it works
Denis Bilenko authored
1
2 To understand how eventlet works, one has to understand how to use greenlet:
3 http://codespeak.net/py/dist/greenlet.html
4
5 * Every greenlet except MAIN has a parent. When an exception happen in the greenlet
6 it is propogated to the parent greenlet (special case is GreenletExit, in that case
7 the greenlet silently dies)
8 * Parent can be reassigned (cycle would be detected and rejected with ValueError)
9
10 ...
11
12 Twisted's reactor and eventlet's hubs are very similar in what they do.
13 Both do select(poll or similar) on the list of known descriptors and call the
14 associated callback in case of an event. In addition, both maintain scheduled calls.
15
16 However, while with twisted you explicitly start the main loop (reactor.run()),
17 with evenlet the main loop is run in a separate greenlet (child of the main greenlet) and
18 is started implicitly. Whenever you want to do a blocking operation, you switch() into
19 the main loop's greenlet with some additional preparations, as shown in the following figure.
20
21 blocking operation RECV on socket d:
22
23 user's greenlet (USER) main loop's greenlet (MAIN_LOOP)
24 |
25 (inside d.recv() call)
26 |
27 add_descriptor(d, RECV)
28 |
29 data=MAIN_LOOP.switch() ---------> poll for events
30 |
31 ... ---------------------------> may execute other greenlets here
32 |
33 event RECV on descriptor d?
34 |
35 data = d.recv() # calling blocking op that will return immediately
36 |
37 return data <------------------- USER.switch(data)
38
Something went wrong with that request. Please try again.