gevent CentOS 6.x Installation Guide
gevent CentOS 6.x Installation Guide
Installation
Requirments
- yum install python python-devel
- yum install libevent-devel
Install Setuptools
install python-setuptools (for easy_install)
yum install python-setuptools
Install greenlet
Install greenlet:
easy_install greenlet
Install gevent
There are several ways to install gevent:
using easy_install (recommended)
easy as:
easy_install gevent
from source
You need wget to download source:
yum install wget
Now, installing gevent: (Check here for the latest package)
cd /tmp wget http://pypi.python.org/packages/source/g/gevent/gevent-0.13.8.tar.gz tar -xvzf gevent-0.13.8.tar.gz cd gevent-0.13.8 python setup.py install
U may need to add –no-check-certificate to the wget if something is wrong.
from GitHub
You can also install gevent from github using pip.
Test
to test simply run in bash:
python
and then:
import gevent
if no error found, you have installed it correctly
First App
Example taken from the community documentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from gevent.wsgi import WSGIServer def application(environ, start_response): status = '200 OK' body = '<p>Hello World</p>' headers = [ ('Content-Type', 'text/html') ] start_response(status, headers) return [body] WSGIServer(('', 8000), application).serve_forever() |
from gevent.wsgi import WSGIServer def application(environ, start_response): status = '200 OK' body = '<p>Hello World</p>' headers = [ ('Content-Type', 'text/html') ] start_response(status, headers) return [body] WSGIServer(('', 8000), application).serve_forever()
copy the example into a file (server.py for ex), and start the server by:
python server.py
and that’s it! browse to the machine on port 8000 using something like this:
http://[ip of the machine]:8000
What’s next..?
Production
In production you can host your gevent after several WSGI server racks like: Gunicorn, Circus, Meinheld, uWSGI, etc..
Gunicorn is the most common WSGI server to host gevent applications. one benchmark shows that Circus is faster then Gunicorn. other tested uWSGI vs Gunicorn and found that uWSGI is faster.
recommend you run them behind a reverse proxy such as nginx. Additional advantages of running them behind a reverse proxy include improved handling of slow clients and bad HTTP requests
SocketIO
You need socketio? you may want to install it:
easy_install gevent-socketio
- socketio documentation
- gevent-socket-io example on GitHub. another one
Read more…
- You should read the gevent documentations.
- great presentation – on gevent; and another presentation: GEvent – whats the point?
- Read the community documentations.
- How we use gevent to go fast – making Pinterest.
need microframework? (flask/bottle)?
You can use a python web framework on top of gevent.
- Python web microframeworks – Take your pick
- Flask vs bottle forum thread.
- Why Flask? (opinion); Simple presentation on Flask
- Simple Interface with flask app.
- Flask example for client/server echo app.
Development Specialist, Artist and Activist
Personal Website