128
128
< header >
129
129
< h1 > < span class ="green "> gevent</ span > For the Working Python Developer</ h1 >
130
130
< h3 class ="author ">
131
- < a href =" http://www.stephendiehl.com " > Stephen Diehl </ a >
131
+ Written by the Gevent Community
132
132
</ h3 >
133
133
</ header >
134
134
@@ -138,6 +138,10 @@ <h3 class="author">
138
138
139
139
< div class ="toc ">
140
140
< ul >
141
+ < li > < a href ="#introduction "> Introduction</ a > < ul >
142
+ < li > < a href ="#contributors "> Contributors</ a > </ li >
143
+ </ ul >
144
+ </ li >
141
145
< li > < a href ="#core "> Core</ a > < ul >
142
146
< li > < a href ="#greenlets "> Greenlets</ a > </ li >
143
147
< li > < a href ="#synchronous-asynchronous-execution "> Synchronous & Asynchronous Execution</ a > </ li >
@@ -172,12 +176,27 @@ <h3 class="author">
172
176
</ li >
173
177
</ ul >
174
178
</ div >
175
- < h1 id ="core " > Core </ h1 >
179
+ < h1 id ="introduction " > Introduction </ h1 >
176
180
< p > The structure of this tutorial assumes an intermediate level
177
181
knowledge of Python but not much else. No knowledge of
178
182
concurrency is expected. The goal is to give you
179
- the tools you need to get going with gevent and use it to solve
180
- or speed up your applications today.</ p >
183
+ the tools you need to get going with gevent, help you tame
184
+ your existing concurrency problems and start writing asynchronous
185
+ applications today.</ p >
186
+ < h3 id ="contributors "> Contributors</ h3 >
187
+ < p > In chronological order of contribution:
188
+ < a href ="http://www.stephendiehl.com "> Stephen Diehl</ a >
189
+ < a href ="https://github.com/jerem "> Jérémy Bethmont</ a >
190
+ < a href ="https://github.com/sww "> sww</ a >
191
+ < a href ="https://github.com/brunoqc "> Bruno Bigras</ a >
192
+ < a href ="https://github.com/dripton "> David Ripton</ a >
193
+ < a href ="https://github.com/traviscline "> Travis Cline</ a >
194
+ < a href ="https://github.com/Lothiraldan "> Boris Feld</ a > </ p >
195
+ < p > This is a collaborative document published under MIT license.
196
+ Have something to add? See a typo? Fork and issue a
197
+ pull request < a href ="https://github.com/sdiehl/gevent-tutorial "> Github</ a > .
198
+ Any and all contributions are welcome.</ p >
199
+ < h1 id ="core "> Core</ h1 >
181
200
< h2 id ="greenlets "> Greenlets</ h2 >
182
201
< p > The primary pattern used in gevent is the < strong > Greenlet</ strong > , a
183
202
lightweight coroutine provided to Python as a C extension module.
@@ -313,16 +332,16 @@ <h2 id="synchronous-asynchronous-execution">Synchronous & Asynchronous Execu
313
332
Task 8 done
314
333
Task 9 done
315
334
Asynchronous:
316
- Task 3 done
317
- Task 5 done
318
- Task 4 done
319
- Task 6 done
320
335
Task 0 done
321
336
Task 2 done
322
- Task 8 done
337
+ Task 6 done
338
+ Task 5 done
339
+ Task 3 done
340
+ Task 4 done
341
+ Task 9 done
323
342
Task 1 done
324
343
Task 7 done
325
- Task 9 done
344
+ Task 8 done
326
345
</ pre > </ code > </ p >
327
346
< p > In the synchronous case all the tasks are run sequentially,
328
347
which results in the main programming < em > blocking</ em > (
@@ -964,6 +983,7 @@ <h2 id="gevent-zeromq">Gevent ZeroMQ</h2>
964
983
gevent-zeromq</ code > </ p >
965
984
< pre > < code class ="python ">
966
985
# Note: Remember to ``pip install pyzmq gevent_zeromq``
986
+ import gevent
967
987
from gevent_zeromq import zmq
968
988
969
989
# Global Context
@@ -981,7 +1001,7 @@ <h2 id="gevent-zeromq">Gevent ZeroMQ</h2>
981
1001
982
1002
def client():
983
1003
client_socket = context.socket(zmq.REP)
984
- client_socket.connect("tcp://* :5000")
1004
+ client_socket.connect("tcp://127.0.0.1 :5000")
985
1005
986
1006
for request in range(1,10):
987
1007
@@ -990,10 +1010,10 @@ <h2 id="gevent-zeromq">Gevent ZeroMQ</h2>
990
1010
# Implicit context switch occurs here
991
1011
client_socket.send("World")
992
1012
993
- publisher = gevent.spawn(server),
994
- client = gevent.spawn(client),
1013
+ publisher = gevent.spawn(server)
1014
+ client = gevent.spawn(client)
995
1015
996
- gevent.joinall( publisher + client )
1016
+ gevent.joinall([ publisher, client] )
997
1017
998
1018
</ pre >
999
1019
0 commit comments