Skip to content

Instantly share code, notes, and snippets.

@denik
Created May 3, 2014 21:15
Show Gist options
  • Save denik/2c451bc515c6b8740b59 to your computer and use it in GitHub Desktop.
Save denik/2c451bc515c6b8740b59 to your computer and use it in GitHub Desktop.
# Unlike Twisted, Tulip and Tornado, gevent can use existing Python libraries:
# Django, Flask, requests, redis-py, SQLAlchemy to name a few
from gevent import monkey; monkey.patch_all()
import gevent
import requests
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return requests.get('http://python.org').content
if __name__ == '__main__':
from gevent import pywsgi
import signal
server = pywsgi.WSGIServer(':8000', app)
server.start()
# graceful shutdown: sending SIGINT/SIGTERM would close the listener
# but keep the process running until the last connection closed
gevent.signal(signal.SIGINT, server.close)
gevent.signal(signal.SIGTERM, server.close)
gevent.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment