Created
September 9, 2015 09:44
-
-
Save ls0f/91ab4313ff2265923d57 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
#coding:utf-8 | |
from gevent import monkey | |
monkey.patch_all() | |
import os | |
import tornado | |
import logging | |
import tornado.wsgi | |
import tornado.httpserver | |
from gevent.pywsgi import WSGIServer | |
from tornado.web import RequestHandler | |
SITE_ROOT = os.path.dirname(__file__) | |
settings = { | |
"static_path":os.path.join(SITE_ROOT,'static'), | |
"template_path":os.path.join(SITE_ROOT,'templates'), | |
"xsrf_cookies": False, | |
"debug": True, | |
} | |
class TestHandler(RequestHandler): | |
def get(self): | |
self.write("OK") | |
urls = [ | |
(r"/", TestHandler), | |
] | |
def main(port): | |
use_gevent = False | |
if use_gevent is False: | |
application = tornado.web.Application(urls, **settings) | |
server = tornado.httpserver.HTTPServer(application,xheaders=True) | |
server.listen(port, address="0.0.0.0") | |
tornado.ioloop.IOLoop.instance().start() | |
else: | |
app = tornado.wsgi.WSGIApplication(urls, **settings) | |
server = WSGIServer(('0.0.0.0', port), app) | |
server.serve_forever() | |
logging.info("Exit...") | |
if __name__ == "__main__": | |
import sys | |
try: | |
port = int(sys.argv[1]) | |
except: | |
port = 8080 | |
main(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment