Created
May 3, 2014 21:15
-
-
Save denik/2c451bc515c6b8740b59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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