Commit 211cc4e3 authored by Denis Bilenko's avatar Denis Bilenko

minor updates in examples; make httpserver and wsgiserver serve on the same port

parent a839ee8d
...@@ -10,7 +10,7 @@ monkey.patch_socket() # patches regular socket to yield to other greenlets ...@@ -10,7 +10,7 @@ monkey.patch_socket() # patches regular socket to yield to other greenlets
import urllib2 import urllib2
from gevent.pool import Pool from gevent.pool import Pool
# Pool accepts one optional argument - a maximum number of concurrent # Pool accepts one optional argument - maximum number of concurrent
# coroutines that can be active at any given moment. # coroutines that can be active at any given moment.
# Try passing 1 or 2 here to see the effect. # Try passing 1 or 2 here to see the effect.
pool = Pool() pool = Pool()
......
"""HTTP server listening on port 8800. #!/usr/bin/python
"""HTTP server example.
Uses libevent API directly and thus may be dangerous. Uses libevent API directly and thus may be dangerous.
WSGI interface is probably a safer choice, see examples/wsgiserver.py. WSGI interface is probably a safer choice, see examples/wsgiserver.py.
...@@ -6,6 +7,7 @@ WSGI interface is probably a safer choice, see examples/wsgiserver.py. ...@@ -6,6 +7,7 @@ WSGI interface is probably a safer choice, see examples/wsgiserver.py.
from gevent import http from gevent import http
def callback(r): def callback(r):
print r
if r.uri == '/': if r.uri == '/':
r.add_output_header('Content-Type', 'text/html') r.add_output_header('Content-Type', 'text/html')
r.send_reply(200, "OK", '<b>hello world</b>') r.send_reply(200, "OK", '<b>hello world</b>')
...@@ -13,5 +15,5 @@ def callback(r): ...@@ -13,5 +15,5 @@ def callback(r):
r.add_output_header('Content-Type', 'text/html') r.add_output_header('Content-Type', 'text/html')
r.send_reply(404, "Not Found", "<h1>Not Found</h1>") r.send_reply(404, "Not Found", "<h1>Not Found</h1>")
print __doc__ print 'Serving on 8088...'
http.HTTPServer(callback).serve_forever(('0.0.0.0', 8800)) http.HTTPServer(callback).serve_forever(('0.0.0.0', 8088))
#/usr/bin/python #!/usr/bin/python
"""Simple wsgi app. Serving on 8088. """WSGI server example"""
"""
from gevent import wsgi2 from gevent import wsgi2
...@@ -12,6 +11,6 @@ def hello_world(env, start_response): ...@@ -12,6 +11,6 @@ def hello_world(env, start_response):
start_response('404 Not Found', [('Content-Type', 'text/plain')]) start_response('404 Not Found', [('Content-Type', 'text/plain')])
return ['Not Found\r\n'] return ['Not Found\r\n']
print __doc__ print 'Serving on 8088...'
wsgi2.WSGIServer(('', 8088), hello_world).serve_forever() wsgi2.WSGIServer(('', 8088), hello_world).serve_forever()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment