Converted docs to use convenience functions.

This commit is contained in:
Ryan Williams
2010-02-21 10:58:08 -05:00
parent fa3a1a0a05
commit bba5fcb0de
2 changed files with 4 additions and 11 deletions

7
doc/design_patterns.rst Normal file → Executable file
View File

@@ -42,7 +42,6 @@ Server Pattern
Here's a simple server-side example, a simple echo server::
import eventlet
from eventlet.green import socket
def handle(client):
while True:
@@ -50,9 +49,7 @@ Here's a simple server-side example, a simple echo server::
if not c: break
client.sendall(c)
server = socket.socket()
server.bind(('0.0.0.0', 6000))
server.listen(50)
server = eventlet.listen(('0.0.0.0', 6000))
pool = eventlet.GreenPool(10000)
while True:
new_sock, address = server.accept()
@@ -60,7 +57,7 @@ Here's a simple server-side example, a simple echo server::
The file :ref:`echo server example <echo_server_example>` contains a somewhat more robust and complex version of this example.
``from eventlet.green import socket`` imports eventlet's socket module, which is just like the regular socket module, but cooperatively yielding.
``server = eventlet.listen(('0.0.0.0', 6000))`` uses a convenience function to create a listening socket.
``pool = eventlet.GreenPool(10000)`` creates a pool of green threads that could handle ten thousand clients.

8
doc/modules/wsgi.rst Normal file → Executable file
View File

@@ -9,17 +9,13 @@ server package. One such package is `Spawning <http://pypi.python.org/pypi/Spaw
To launch a wsgi server, simply create a socket and call :func:`eventlet.wsgi.server` with it::
from eventlet import wsgi
from eventlet.green import socket
import eventlet
def hello_world(env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello, World!\r\n']
sock = socket.socket()
sock.bind(('', 8090))
sock.listen(500)
wsgi.server(sock, hello_world)
wsgi.server(eventlet.listen(('', 8090)), hello_world)
You can find a slightly more elaborate version of this code in the file